blob: 98b22303c84d1849da10221e80cfce7d87568c5a [file] [log] [blame]
Larry Finger0c817332010-12-08 11:12:31 -06001/******************************************************************************
2 *
Larry Finger9003a4a2012-01-07 20:46:44 -06003 * Copyright(c) 2009-2012 Realtek Corporation.
Larry Finger0c817332010-12-08 11:12:31 -06004 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
20 *
21 * Contact Information:
22 * wlanfae <wlanfae@realtek.com>
23 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
24 * Hsinchu 300, Taiwan.
25 *
26 * Larry Finger <Larry.Finger@lwfinger.net>
27 *
28 *****************************************************************************/
29
30#include "../wifi.h"
31#include "../pci.h"
32#include "../ps.h"
Larry Finger25b13db2014-03-04 16:53:48 -060033#include "../core.h"
John W. Linville5c405b52010-12-16 15:43:36 -050034#include "reg.h"
35#include "def.h"
Larry Finger1472d3a2011-02-23 10:24:58 -060036#include "hw.h"
John W. Linville5c405b52010-12-16 15:43:36 -050037#include "phy.h"
38#include "rf.h"
39#include "dm.h"
40#include "table.h"
Larry Finger0c817332010-12-08 11:12:31 -060041
Chaoming_Lie0b5a502011-04-25 12:54:00 -050042static bool _rtl92c_phy_config_mac_with_headerfile(struct ieee80211_hw *hw);
43
44u32 rtl92c_phy_query_rf_reg(struct ieee80211_hw *hw,
Larry Finger0c817332010-12-08 11:12:31 -060045 enum radio_path rfpath, u32 regaddr, u32 bitmask)
46{
47 struct rtl_priv *rtlpriv = rtl_priv(hw);
48 u32 original_value, readback_value, bitshift;
49 struct rtl_phy *rtlphy = &(rtlpriv->phy);
Larry Finger0c817332010-12-08 11:12:31 -060050
Joe Perchesf30d7502012-01-04 19:40:41 -080051 RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE,
52 "regaddr(%#x), rfpath(%#x), bitmask(%#x)\n",
53 regaddr, rfpath, bitmask);
Larry Finger0c817332010-12-08 11:12:31 -060054
Mike McCormack312d5472011-05-31 08:49:36 +090055 spin_lock(&rtlpriv->locks.rf_lock);
Larry Finger0c817332010-12-08 11:12:31 -060056
57 if (rtlphy->rf_mode != RF_OP_BY_FW) {
58 original_value = _rtl92c_phy_rf_serial_read(hw,
59 rfpath, regaddr);
60 } else {
61 original_value = _rtl92c_phy_fw_rf_serial_read(hw,
62 rfpath, regaddr);
63 }
64
65 bitshift = _rtl92c_phy_calculate_bit_shift(bitmask);
66 readback_value = (original_value & bitmask) >> bitshift;
67
Mike McCormack312d5472011-05-31 08:49:36 +090068 spin_unlock(&rtlpriv->locks.rf_lock);
Larry Finger0c817332010-12-08 11:12:31 -060069
70 RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE,
Joe Perchesf30d7502012-01-04 19:40:41 -080071 "regaddr(%#x), rfpath(%#x), bitmask(%#x), original_value(%#x)\n",
72 regaddr, rfpath, bitmask, original_value);
Larry Finger0c817332010-12-08 11:12:31 -060073
74 return readback_value;
75}
76
Chaoming_Lie0b5a502011-04-25 12:54:00 -050077bool rtl92c_phy_mac_config(struct ieee80211_hw *hw)
78{
79 struct rtl_priv *rtlpriv = rtl_priv(hw);
80 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
81 bool is92c = IS_92C_SERIAL(rtlhal->version);
82 bool rtstatus = _rtl92c_phy_config_mac_with_headerfile(hw);
83
84 if (is92c)
85 rtl_write_byte(rtlpriv, 0x14, 0x71);
Larry Finger0bd899e2012-10-25 13:46:30 -050086 else
87 rtl_write_byte(rtlpriv, 0x04CA, 0x0A);
Chaoming_Lie0b5a502011-04-25 12:54:00 -050088 return rtstatus;
89}
90
91bool rtl92c_phy_bb_config(struct ieee80211_hw *hw)
92{
93 bool rtstatus = true;
94 struct rtl_priv *rtlpriv = rtl_priv(hw);
95 u16 regval;
96 u32 regvaldw;
97 u8 reg_hwparafile = 1;
98
99 _rtl92c_phy_init_bb_rf_register_definition(hw);
100 regval = rtl_read_word(rtlpriv, REG_SYS_FUNC_EN);
101 rtl_write_word(rtlpriv, REG_SYS_FUNC_EN,
102 regval | BIT(13) | BIT(0) | BIT(1));
103 rtl_write_byte(rtlpriv, REG_AFE_PLL_CTRL, 0x83);
104 rtl_write_byte(rtlpriv, REG_AFE_PLL_CTRL + 1, 0xdb);
105 rtl_write_byte(rtlpriv, REG_RF_CTRL, RF_EN | RF_RSTB | RF_SDMRSTB);
106 rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN,
107 FEN_PPLL | FEN_PCIEA | FEN_DIO_PCIE |
108 FEN_BB_GLB_RSTn | FEN_BBRSTB);
109 rtl_write_byte(rtlpriv, REG_AFE_XTAL_CTRL + 1, 0x80);
110 regvaldw = rtl_read_dword(rtlpriv, REG_LEDCFG0);
111 rtl_write_dword(rtlpriv, REG_LEDCFG0, regvaldw | BIT(23));
112 if (reg_hwparafile == 1)
113 rtstatus = _rtl92c_phy_bb8192c_config_parafile(hw);
114 return rtstatus;
115}
116
Larry Finger1472d3a2011-02-23 10:24:58 -0600117void rtl92ce_phy_set_rf_reg(struct ieee80211_hw *hw,
Chaoming_Lie0b5a502011-04-25 12:54:00 -0500118 enum radio_path rfpath,
119 u32 regaddr, u32 bitmask, u32 data)
Larry Finger0c817332010-12-08 11:12:31 -0600120{
121 struct rtl_priv *rtlpriv = rtl_priv(hw);
122 struct rtl_phy *rtlphy = &(rtlpriv->phy);
123 u32 original_value, bitshift;
Larry Finger0c817332010-12-08 11:12:31 -0600124
125 RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE,
Joe Perchesf30d7502012-01-04 19:40:41 -0800126 "regaddr(%#x), bitmask(%#x), data(%#x), rfpath(%#x)\n",
127 regaddr, bitmask, data, rfpath);
Larry Finger0c817332010-12-08 11:12:31 -0600128
Mike McCormack312d5472011-05-31 08:49:36 +0900129 spin_lock(&rtlpriv->locks.rf_lock);
Larry Finger0c817332010-12-08 11:12:31 -0600130
131 if (rtlphy->rf_mode != RF_OP_BY_FW) {
132 if (bitmask != RFREG_OFFSET_MASK) {
133 original_value = _rtl92c_phy_rf_serial_read(hw,
134 rfpath,
135 regaddr);
136 bitshift = _rtl92c_phy_calculate_bit_shift(bitmask);
137 data =
138 ((original_value & (~bitmask)) |
139 (data << bitshift));
140 }
141
142 _rtl92c_phy_rf_serial_write(hw, rfpath, regaddr, data);
143 } else {
144 if (bitmask != RFREG_OFFSET_MASK) {
145 original_value = _rtl92c_phy_fw_rf_serial_read(hw,
146 rfpath,
147 regaddr);
148 bitshift = _rtl92c_phy_calculate_bit_shift(bitmask);
149 data =
150 ((original_value & (~bitmask)) |
151 (data << bitshift));
152 }
153 _rtl92c_phy_fw_rf_serial_write(hw, rfpath, regaddr, data);
154 }
155
Mike McCormack312d5472011-05-31 08:49:36 +0900156 spin_unlock(&rtlpriv->locks.rf_lock);
Larry Finger0c817332010-12-08 11:12:31 -0600157
Joe Perchesf30d7502012-01-04 19:40:41 -0800158 RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE,
159 "regaddr(%#x), bitmask(%#x), data(%#x), rfpath(%#x)\n",
160 regaddr, bitmask, data, rfpath);
Larry Finger0c817332010-12-08 11:12:31 -0600161}
162
Chaoming_Lie0b5a502011-04-25 12:54:00 -0500163static bool _rtl92c_phy_config_mac_with_headerfile(struct ieee80211_hw *hw)
Larry Finger0c817332010-12-08 11:12:31 -0600164{
165 struct rtl_priv *rtlpriv = rtl_priv(hw);
166 u32 i;
167 u32 arraylength;
168 u32 *ptrarray;
169
Joe Perchesf30d7502012-01-04 19:40:41 -0800170 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "Read Rtl819XMACPHY_Array\n");
Larry Finger0c817332010-12-08 11:12:31 -0600171 arraylength = MAC_2T_ARRAYLENGTH;
172 ptrarray = RTL8192CEMAC_2T_ARRAY;
Joe Perchesf30d7502012-01-04 19:40:41 -0800173 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "Img:RTL8192CEMAC_2T_ARRAY\n");
Larry Finger0c817332010-12-08 11:12:31 -0600174 for (i = 0; i < arraylength; i = i + 2)
175 rtl_write_byte(rtlpriv, ptrarray[i], (u8) ptrarray[i + 1]);
176 return true;
177}
178
Larry Finger1472d3a2011-02-23 10:24:58 -0600179bool _rtl92ce_phy_config_bb_with_headerfile(struct ieee80211_hw *hw,
Chaoming_Lie0b5a502011-04-25 12:54:00 -0500180 u8 configtype)
Larry Finger0c817332010-12-08 11:12:31 -0600181{
182 int i;
183 u32 *phy_regarray_table;
184 u32 *agctab_array_table;
185 u16 phy_reg_arraylen, agctab_arraylen;
186 struct rtl_priv *rtlpriv = rtl_priv(hw);
187 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
188
189 if (IS_92C_SERIAL(rtlhal->version)) {
190 agctab_arraylen = AGCTAB_2TARRAYLENGTH;
191 agctab_array_table = RTL8192CEAGCTAB_2TARRAY;
192 phy_reg_arraylen = PHY_REG_2TARRAY_LENGTH;
193 phy_regarray_table = RTL8192CEPHY_REG_2TARRAY;
194 } else {
195 agctab_arraylen = AGCTAB_1TARRAYLENGTH;
196 agctab_array_table = RTL8192CEAGCTAB_1TARRAY;
197 phy_reg_arraylen = PHY_REG_1TARRAY_LENGTH;
198 phy_regarray_table = RTL8192CEPHY_REG_1TARRAY;
199 }
200 if (configtype == BASEBAND_CONFIG_PHY_REG) {
201 for (i = 0; i < phy_reg_arraylen; i = i + 2) {
Larry Finger25b13db2014-03-04 16:53:48 -0600202 rtl_addr_delay(phy_regarray_table[i]);
Larry Finger0c817332010-12-08 11:12:31 -0600203 rtl_set_bbreg(hw, phy_regarray_table[i], MASKDWORD,
204 phy_regarray_table[i + 1]);
205 udelay(1);
206 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
Joe Perchesf30d7502012-01-04 19:40:41 -0800207 "The phy_regarray_table[0] is %x Rtl819XPHY_REGArray[1] is %x\n",
208 phy_regarray_table[i],
209 phy_regarray_table[i + 1]);
Larry Finger0c817332010-12-08 11:12:31 -0600210 }
Larry Finger0c817332010-12-08 11:12:31 -0600211 } else if (configtype == BASEBAND_CONFIG_AGC_TAB) {
212 for (i = 0; i < agctab_arraylen; i = i + 2) {
213 rtl_set_bbreg(hw, agctab_array_table[i], MASKDWORD,
214 agctab_array_table[i + 1]);
215 udelay(1);
216 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
Joe Perchesf30d7502012-01-04 19:40:41 -0800217 "The agctab_array_table[0] is %x Rtl819XPHY_REGArray[1] is %x\n",
218 agctab_array_table[i],
219 agctab_array_table[i + 1]);
Larry Finger0c817332010-12-08 11:12:31 -0600220 }
221 }
222 return true;
223}
224
Larry Finger1472d3a2011-02-23 10:24:58 -0600225bool _rtl92ce_phy_config_bb_with_pgheaderfile(struct ieee80211_hw *hw,
Chaoming_Lie0b5a502011-04-25 12:54:00 -0500226 u8 configtype)
Larry Finger0c817332010-12-08 11:12:31 -0600227{
228 struct rtl_priv *rtlpriv = rtl_priv(hw);
229 int i;
230 u32 *phy_regarray_table_pg;
231 u16 phy_regarray_pg_len;
232
233 phy_regarray_pg_len = PHY_REG_ARRAY_PGLENGTH;
234 phy_regarray_table_pg = RTL8192CEPHY_REG_ARRAY_PG;
235
236 if (configtype == BASEBAND_CONFIG_PHY_REG) {
237 for (i = 0; i < phy_regarray_pg_len; i = i + 3) {
Larry Finger25b13db2014-03-04 16:53:48 -0600238 rtl_addr_delay(phy_regarray_table_pg[i]);
Larry Finger0c817332010-12-08 11:12:31 -0600239
240 _rtl92c_store_pwrIndex_diffrate_offset(hw,
241 phy_regarray_table_pg[i],
242 phy_regarray_table_pg[i + 1],
243 phy_regarray_table_pg[i + 2]);
244 }
245 } else {
246
247 RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
Joe Perchesf30d7502012-01-04 19:40:41 -0800248 "configtype != BaseBand_Config_PHY_REG\n");
Larry Finger0c817332010-12-08 11:12:31 -0600249 }
250 return true;
251}
252
Chaoming_Lie0b5a502011-04-25 12:54:00 -0500253bool rtl92c_phy_config_rf_with_headerfile(struct ieee80211_hw *hw,
Larry Finger0c817332010-12-08 11:12:31 -0600254 enum radio_path rfpath)
255{
256
257 int i;
Larry Finger0c817332010-12-08 11:12:31 -0600258 u32 *radioa_array_table;
259 u32 *radiob_array_table;
260 u16 radioa_arraylen, radiob_arraylen;
261 struct rtl_priv *rtlpriv = rtl_priv(hw);
262 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
263
264 if (IS_92C_SERIAL(rtlhal->version)) {
265 radioa_arraylen = RADIOA_2TARRAYLENGTH;
266 radioa_array_table = RTL8192CERADIOA_2TARRAY;
267 radiob_arraylen = RADIOB_2TARRAYLENGTH;
268 radiob_array_table = RTL8192CE_RADIOB_2TARRAY;
269 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
Joe Perchesf30d7502012-01-04 19:40:41 -0800270 "Radio_A:RTL8192CERADIOA_2TARRAY\n");
Larry Finger0c817332010-12-08 11:12:31 -0600271 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
Joe Perchesf30d7502012-01-04 19:40:41 -0800272 "Radio_B:RTL8192CE_RADIOB_2TARRAY\n");
Larry Finger0c817332010-12-08 11:12:31 -0600273 } else {
274 radioa_arraylen = RADIOA_1TARRAYLENGTH;
275 radioa_array_table = RTL8192CE_RADIOA_1TARRAY;
276 radiob_arraylen = RADIOB_1TARRAYLENGTH;
277 radiob_array_table = RTL8192CE_RADIOB_1TARRAY;
278 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
Joe Perchesf30d7502012-01-04 19:40:41 -0800279 "Radio_A:RTL8192CE_RADIOA_1TARRAY\n");
Larry Finger0c817332010-12-08 11:12:31 -0600280 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
Joe Perchesf30d7502012-01-04 19:40:41 -0800281 "Radio_B:RTL8192CE_RADIOB_1TARRAY\n");
Larry Finger0c817332010-12-08 11:12:31 -0600282 }
Joe Perchesf30d7502012-01-04 19:40:41 -0800283 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "Radio No %x\n", rfpath);
Larry Finger0c817332010-12-08 11:12:31 -0600284 switch (rfpath) {
285 case RF90_PATH_A:
286 for (i = 0; i < radioa_arraylen; i = i + 2) {
Larry Finger25b13db2014-03-04 16:53:48 -0600287 rtl_rfreg_delay(hw, rfpath, radioa_array_table[i],
288 RFREG_OFFSET_MASK,
289 radioa_array_table[i + 1]);
Larry Finger0c817332010-12-08 11:12:31 -0600290 }
Larry Finger0c817332010-12-08 11:12:31 -0600291 break;
292 case RF90_PATH_B:
293 for (i = 0; i < radiob_arraylen; i = i + 2) {
Larry Finger25b13db2014-03-04 16:53:48 -0600294 rtl_rfreg_delay(hw, rfpath, radiob_array_table[i],
295 RFREG_OFFSET_MASK,
296 radiob_array_table[i + 1]);
Larry Finger0c817332010-12-08 11:12:31 -0600297 }
298 break;
299 case RF90_PATH_C:
300 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
Joe Perchesf30d7502012-01-04 19:40:41 -0800301 "switch case not processed\n");
Larry Finger0c817332010-12-08 11:12:31 -0600302 break;
303 case RF90_PATH_D:
304 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
Joe Perchesf30d7502012-01-04 19:40:41 -0800305 "switch case not processed\n");
Larry Finger0c817332010-12-08 11:12:31 -0600306 break;
Larry Finger25b13db2014-03-04 16:53:48 -0600307 default:
308 break;
Larry Finger0c817332010-12-08 11:12:31 -0600309 }
310 return true;
311}
312
Larry Finger099fb8a2011-05-14 10:15:17 -0500313void rtl92ce_phy_set_bw_mode_callback(struct ieee80211_hw *hw)
314{
315 struct rtl_priv *rtlpriv = rtl_priv(hw);
316 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
317 struct rtl_phy *rtlphy = &(rtlpriv->phy);
318 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
319 u8 reg_bw_opmode;
320 u8 reg_prsr_rsc;
321
Joe Perchesf30d7502012-01-04 19:40:41 -0800322 RT_TRACE(rtlpriv, COMP_SCAN, DBG_TRACE, "Switch to %s bandwidth\n",
323 rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20 ?
324 "20MHz" : "40MHz");
Larry Finger099fb8a2011-05-14 10:15:17 -0500325
326 if (is_hal_stop(rtlhal)) {
327 rtlphy->set_bwmode_inprogress = false;
328 return;
329 }
330
331 reg_bw_opmode = rtl_read_byte(rtlpriv, REG_BWOPMODE);
332 reg_prsr_rsc = rtl_read_byte(rtlpriv, REG_RRSR + 2);
333
334 switch (rtlphy->current_chan_bw) {
335 case HT_CHANNEL_WIDTH_20:
336 reg_bw_opmode |= BW_OPMODE_20MHZ;
337 rtl_write_byte(rtlpriv, REG_BWOPMODE, reg_bw_opmode);
338 break;
339 case HT_CHANNEL_WIDTH_20_40:
340 reg_bw_opmode &= ~BW_OPMODE_20MHZ;
341 rtl_write_byte(rtlpriv, REG_BWOPMODE, reg_bw_opmode);
342 reg_prsr_rsc =
343 (reg_prsr_rsc & 0x90) | (mac->cur_40_prime_sc << 5);
344 rtl_write_byte(rtlpriv, REG_RRSR + 2, reg_prsr_rsc);
345 break;
346 default:
347 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
Joe Perchesf30d7502012-01-04 19:40:41 -0800348 "unknown bandwidth: %#X\n", rtlphy->current_chan_bw);
Larry Finger099fb8a2011-05-14 10:15:17 -0500349 break;
350 }
351
352 switch (rtlphy->current_chan_bw) {
353 case HT_CHANNEL_WIDTH_20:
354 rtl_set_bbreg(hw, RFPGA0_RFMOD, BRFMOD, 0x0);
355 rtl_set_bbreg(hw, RFPGA1_RFMOD, BRFMOD, 0x0);
356 rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER2, BIT(10), 1);
357 break;
358 case HT_CHANNEL_WIDTH_20_40:
359 rtl_set_bbreg(hw, RFPGA0_RFMOD, BRFMOD, 0x1);
360 rtl_set_bbreg(hw, RFPGA1_RFMOD, BRFMOD, 0x1);
361
362 rtl_set_bbreg(hw, RCCK0_SYSTEM, BCCK_SIDEBAND,
363 (mac->cur_40_prime_sc >> 1));
364 rtl_set_bbreg(hw, ROFDM1_LSTF, 0xC00, mac->cur_40_prime_sc);
365 rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER2, BIT(10), 0);
366
367 rtl_set_bbreg(hw, 0x818, (BIT(26) | BIT(27)),
368 (mac->cur_40_prime_sc ==
369 HAL_PRIME_CHNL_OFFSET_LOWER) ? 2 : 1);
370 break;
371 default:
372 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
Joe Perchesf30d7502012-01-04 19:40:41 -0800373 "unknown bandwidth: %#X\n", rtlphy->current_chan_bw);
Larry Finger099fb8a2011-05-14 10:15:17 -0500374 break;
375 }
376 rtl92ce_phy_rf6052_set_bandwidth(hw, rtlphy->current_chan_bw);
377 rtlphy->set_bwmode_inprogress = false;
Joe Perchesf30d7502012-01-04 19:40:41 -0800378 RT_TRACE(rtlpriv, COMP_SCAN, DBG_TRACE, "<==\n");
Larry Finger099fb8a2011-05-14 10:15:17 -0500379}
380
Larry Finger1472d3a2011-02-23 10:24:58 -0600381void _rtl92ce_phy_lc_calibrate(struct ieee80211_hw *hw, bool is2t)
Larry Finger0c817332010-12-08 11:12:31 -0600382{
383 u8 tmpreg;
384 u32 rf_a_mode = 0, rf_b_mode = 0, lc_cal;
385 struct rtl_priv *rtlpriv = rtl_priv(hw);
386
387 tmpreg = rtl_read_byte(rtlpriv, 0xd03);
388
389 if ((tmpreg & 0x70) != 0)
390 rtl_write_byte(rtlpriv, 0xd03, tmpreg & 0x8F);
391 else
392 rtl_write_byte(rtlpriv, REG_TXPAUSE, 0xFF);
393
394 if ((tmpreg & 0x70) != 0) {
395 rf_a_mode = rtl_get_rfreg(hw, RF90_PATH_A, 0x00, MASK12BITS);
396
397 if (is2t)
398 rf_b_mode = rtl_get_rfreg(hw, RF90_PATH_B, 0x00,
399 MASK12BITS);
400
401 rtl_set_rfreg(hw, RF90_PATH_A, 0x00, MASK12BITS,
402 (rf_a_mode & 0x8FFFF) | 0x10000);
403
404 if (is2t)
405 rtl_set_rfreg(hw, RF90_PATH_B, 0x00, MASK12BITS,
406 (rf_b_mode & 0x8FFFF) | 0x10000);
407 }
408 lc_cal = rtl_get_rfreg(hw, RF90_PATH_A, 0x18, MASK12BITS);
409
410 rtl_set_rfreg(hw, RF90_PATH_A, 0x18, MASK12BITS, lc_cal | 0x08000);
411
412 mdelay(100);
413
414 if ((tmpreg & 0x70) != 0) {
415 rtl_write_byte(rtlpriv, 0xd03, tmpreg);
416 rtl_set_rfreg(hw, RF90_PATH_A, 0x00, MASK12BITS, rf_a_mode);
417
418 if (is2t)
419 rtl_set_rfreg(hw, RF90_PATH_B, 0x00, MASK12BITS,
420 rf_b_mode);
421 } else {
422 rtl_write_byte(rtlpriv, REG_TXPAUSE, 0x00);
423 }
424}
425
Chaoming_Lie0b5a502011-04-25 12:54:00 -0500426static void _rtl92ce_phy_set_rf_sleep(struct ieee80211_hw *hw)
427{
428 u32 u4b_tmp;
429 u8 delay = 5;
430 struct rtl_priv *rtlpriv = rtl_priv(hw);
431
432 rtl_write_byte(rtlpriv, REG_TXPAUSE, 0xFF);
433 rtl_set_rfreg(hw, RF90_PATH_A, 0x00, RFREG_OFFSET_MASK, 0x00);
434 rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x40);
435 u4b_tmp = rtl_get_rfreg(hw, RF90_PATH_A, 0, RFREG_OFFSET_MASK);
436 while (u4b_tmp != 0 && delay > 0) {
437 rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x0);
438 rtl_set_rfreg(hw, RF90_PATH_A, 0x00, RFREG_OFFSET_MASK, 0x00);
439 rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x40);
440 u4b_tmp = rtl_get_rfreg(hw, RF90_PATH_A, 0, RFREG_OFFSET_MASK);
441 delay--;
442 }
443 if (delay == 0) {
444 rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x00);
445 rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE2);
446 rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE3);
447 rtl_write_byte(rtlpriv, REG_TXPAUSE, 0x00);
448 RT_TRACE(rtlpriv, COMP_POWER, DBG_TRACE,
Joe Perchesf30d7502012-01-04 19:40:41 -0800449 "Switch RF timeout !!!\n");
Chaoming_Lie0b5a502011-04-25 12:54:00 -0500450 return;
451 }
452 rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE2);
453 rtl_write_byte(rtlpriv, REG_SPS0_CTRL, 0x22);
454}
455
Larry Finger0c817332010-12-08 11:12:31 -0600456static bool _rtl92ce_phy_set_rf_power_state(struct ieee80211_hw *hw,
457 enum rf_pwrstate rfpwr_state)
458{
459 struct rtl_priv *rtlpriv = rtl_priv(hw);
460 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
461 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
462 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
463 bool bresult = true;
464 u8 i, queue_id;
465 struct rtl8192_tx_ring *ring = NULL;
466
Larry Finger0c817332010-12-08 11:12:31 -0600467 switch (rfpwr_state) {
468 case ERFON:{
469 if ((ppsc->rfpwr_state == ERFOFF) &&
470 RT_IN_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC)) {
471 bool rtstatus;
472 u32 InitializeCount = 0;
473 do {
474 InitializeCount++;
475 RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
Joe Perchesf30d7502012-01-04 19:40:41 -0800476 "IPS Set eRf nic enable\n");
Larry Finger0c817332010-12-08 11:12:31 -0600477 rtstatus = rtl_ps_enable_nic(hw);
Joe Perches23677ce2012-02-09 11:17:23 +0000478 } while (!rtstatus && (InitializeCount < 10));
Larry Finger0c817332010-12-08 11:12:31 -0600479 RT_CLEAR_PS_LEVEL(ppsc,
480 RT_RF_OFF_LEVL_HALT_NIC);
481 } else {
482 RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
Joe Perchesf30d7502012-01-04 19:40:41 -0800483 "Set ERFON sleeped:%d ms\n",
484 jiffies_to_msecs(jiffies -
485 ppsc->
486 last_sleep_jiffies));
Larry Finger0c817332010-12-08 11:12:31 -0600487 ppsc->last_awake_jiffies = jiffies;
488 rtl92ce_phy_set_rf_on(hw);
489 }
490 if (mac->link_state == MAC80211_LINKED) {
491 rtlpriv->cfg->ops->led_control(hw,
492 LED_CTL_LINK);
493 } else {
494 rtlpriv->cfg->ops->led_control(hw,
495 LED_CTL_NO_LINK);
496 }
497 break;
498 }
499 case ERFOFF:{
Larry Finger0c817332010-12-08 11:12:31 -0600500 if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_HALT_NIC) {
501 RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
Joe Perchesf30d7502012-01-04 19:40:41 -0800502 "IPS Set eRf nic disable\n");
Larry Finger0c817332010-12-08 11:12:31 -0600503 rtl_ps_disable_nic(hw);
504 RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC);
505 } else {
506 if (ppsc->rfoff_reason == RF_CHANGE_BY_IPS) {
507 rtlpriv->cfg->ops->led_control(hw,
508 LED_CTL_NO_LINK);
509 } else {
510 rtlpriv->cfg->ops->led_control(hw,
511 LED_CTL_POWER_OFF);
512 }
513 }
514 break;
515 }
516 case ERFSLEEP:{
517 if (ppsc->rfpwr_state == ERFOFF)
Philipp Dreimann91ddff82011-12-07 13:43:31 -0600518 return false;
Larry Finger0c817332010-12-08 11:12:31 -0600519 for (queue_id = 0, i = 0;
520 queue_id < RTL_PCI_MAX_TX_QUEUE_COUNT;) {
521 ring = &pcipriv->dev.tx_ring[queue_id];
522 if (skb_queue_len(&ring->queue) == 0) {
523 queue_id++;
524 continue;
525 } else {
526 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
Joe Perchesf30d7502012-01-04 19:40:41 -0800527 "eRf Off/Sleep: %d times TcbBusyQueue[%d] =%d before doze!\n",
528 i + 1, queue_id,
529 skb_queue_len(&ring->queue));
Chaoming_Lie0b5a502011-04-25 12:54:00 -0500530
Larry Finger0c817332010-12-08 11:12:31 -0600531 udelay(10);
532 i++;
533 }
534 if (i >= MAX_DOZE_WAITING_TIMES_9x) {
535 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
Joe Perchesf30d7502012-01-04 19:40:41 -0800536 "ERFSLEEP: %d times TcbBusyQueue[%d] = %d !\n",
537 MAX_DOZE_WAITING_TIMES_9x,
538 queue_id,
539 skb_queue_len(&ring->queue));
Larry Finger0c817332010-12-08 11:12:31 -0600540 break;
541 }
542 }
543 RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
Joe Perchesf30d7502012-01-04 19:40:41 -0800544 "Set ERFSLEEP awaked:%d ms\n",
545 jiffies_to_msecs(jiffies -
546 ppsc->last_awake_jiffies));
Larry Finger0c817332010-12-08 11:12:31 -0600547 ppsc->last_sleep_jiffies = jiffies;
Chaoming_Lie0b5a502011-04-25 12:54:00 -0500548 _rtl92ce_phy_set_rf_sleep(hw);
Larry Finger0c817332010-12-08 11:12:31 -0600549 break;
550 }
551 default:
552 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
Joe Perchesf30d7502012-01-04 19:40:41 -0800553 "switch case not processed\n");
Larry Finger0c817332010-12-08 11:12:31 -0600554 bresult = false;
555 break;
556 }
557 if (bresult)
558 ppsc->rfpwr_state = rfpwr_state;
Larry Finger0c817332010-12-08 11:12:31 -0600559 return bresult;
560}
561
Chaoming_Lie0b5a502011-04-25 12:54:00 -0500562bool rtl92c_phy_set_rf_power_state(struct ieee80211_hw *hw,
Larry Finger0c817332010-12-08 11:12:31 -0600563 enum rf_pwrstate rfpwr_state)
564{
565 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
Chaoming_Lie0b5a502011-04-25 12:54:00 -0500566
Larry Finger0c817332010-12-08 11:12:31 -0600567 bool bresult = false;
568
569 if (rfpwr_state == ppsc->rfpwr_state)
570 return bresult;
571 bresult = _rtl92ce_phy_set_rf_power_state(hw, rfpwr_state);
572 return bresult;
573}