1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#ifndef __RTW_PWRCTRL_H_
21#define __RTW_PWRCTRL_H_
22
23#include <osdep_service.h>
24#include <drv_types.h>
25
26#define FW_PWR0 0
27#define FW_PWR1 1
28#define FW_PWR2 2
29#define FW_PWR3 3
30#define HW_PWR0 7
31#define HW_PWR1 6
32#define HW_PWR2 2
33#define HW_PWR3 0
34#define HW_PWR4 8
35
36#define FW_PWRMSK 0x7
37
38#define XMIT_ALIVE BIT(0)
39#define RECV_ALIVE BIT(1)
40#define CMD_ALIVE BIT(2)
41#define EVT_ALIVE BIT(3)
42
43enum power_mgnt {
44 PS_MODE_ACTIVE = 0,
45 PS_MODE_MIN,
46 PS_MODE_MAX,
47 PS_MODE_DTIM,
48 PS_MODE_VOIP,
49 PS_MODE_UAPSD_WMM,
50 PS_MODE_UAPSD,
51 PS_MODE_IBSS,
52 PS_MODE_WWLAN,
53 PM_Radio_Off,
54 PM_Card_Disable,
55 PS_MODE_NUM
56};
57
58
59
60
61
62
63
64
65#define PS_DPS BIT(0)
66#define PS_LCLK (PS_DPS)
67#define PS_RF_OFF BIT(1)
68#define PS_ALL_ON BIT(2)
69#define PS_ST_ACTIVE BIT(3)
70
71#define PS_ISR_ENABLE BIT(4)
72#define PS_IMR_ENABLE BIT(5)
73#define PS_ACK BIT(6)
74#define PS_TOGGLE BIT(7)
75
76#define PS_STATE_MASK (0x0F)
77#define PS_STATE_HW_MASK (0x07)
78#define PS_SEQ_MASK (0xc0)
79
80#define PS_STATE(x) (PS_STATE_MASK & (x))
81#define PS_STATE_HW(x) (PS_STATE_HW_MASK & (x))
82#define PS_SEQ(x) (PS_SEQ_MASK & (x))
83
84#define PS_STATE_S0 (PS_DPS)
85#define PS_STATE_S1 (PS_LCLK)
86#define PS_STATE_S2 (PS_RF_OFF)
87#define PS_STATE_S3 (PS_ALL_ON)
88#define PS_STATE_S4 ((PS_ST_ACTIVE) | (PS_ALL_ON))
89
90#define PS_IS_RF_ON(x) ((x) & (PS_ALL_ON))
91#define PS_IS_ACTIVE(x) ((x) & (PS_ST_ACTIVE))
92#define CLR_PS_STATE(x) ((x) = ((x) & (0xF0)))
93
94struct reportpwrstate_parm {
95 unsigned char mode;
96 unsigned char state;
97 unsigned short rsvd;
98};
99
100static inline void _init_pwrlock(struct semaphore *plock)
101{
102 _rtw_init_sema(plock, 1);
103}
104
105static inline void _free_pwrlock(struct semaphore *plock)
106{
107 _rtw_free_sema(plock);
108}
109
110static inline void _enter_pwrlock(struct semaphore *plock)
111{
112 _rtw_down_sema(plock);
113}
114
115static inline void _exit_pwrlock(struct semaphore *plock)
116{
117 _rtw_up_sema(plock);
118}
119
120#define LPS_DELAY_TIME 1*HZ
121
122#define EXE_PWR_NONE 0x01
123#define EXE_PWR_IPS 0x02
124#define EXE_PWR_LPS 0x04
125
126
127enum rt_rf_power_state {
128 rf_on,
129 rf_sleep,
130 rf_off,
131
132 rf_max
133};
134
135
136#define RT_RF_OFF_LEVL_ASPM BIT(0)
137#define RT_RF_OFF_LEVL_CLK_REQ BIT(1)
138#define RT_RF_OFF_LEVL_PCI_D3 BIT(2)
139#define RT_RF_OFF_LEVL_HALT_NIC BIT(3)
140#define RT_RF_OFF_LEVL_FREE_FW BIT(4)
141#define RT_RF_OFF_LEVL_FW_32K BIT(5)
142#define RT_RF_PS_LEVEL_ALWAYS_ASPM BIT(6)
143
144#define RT_RF_LPS_DISALBE_2R BIT(30)
145
146#define RT_RF_LPS_LEVEL_ASPM BIT(31)
147
148#define RT_IN_PS_LEVEL(ppsc, _PS_FLAG) \
149 ((ppsc->cur_ps_level & _PS_FLAG) ? true : false)
150#define RT_CLEAR_PS_LEVEL(ppsc, _PS_FLAG) \
151 (ppsc->cur_ps_level &= (~(_PS_FLAG)))
152#define RT_SET_PS_LEVEL(ppsc, _PS_FLAG) \
153 (ppsc->cur_ps_level |= _PS_FLAG)
154
155enum _PS_BBRegBackup_ {
156 PSBBREG_RF0 = 0,
157 PSBBREG_RF1,
158 PSBBREG_RF2,
159 PSBBREG_AFE0,
160 PSBBREG_TOTALCNT
161};
162
163enum {
164 IPS_NONE = 0,
165 IPS_NORMAL,
166 IPS_LEVEL_2,
167};
168
169struct pwrctrl_priv {
170 struct semaphore lock;
171 volatile u8 rpwm;
172 volatile u8 cpwm;
173
174 volatile u8 tog;
175 volatile u8 cpwm_tog;
176
177 u8 pwr_mode;
178 u8 smart_ps;
179 u8 bcn_ant_mode;
180
181 u32 alives;
182 struct work_struct cpwm_event;
183 u8 bpower_saving;
184
185 u8 b_hw_radio_off;
186 u8 reg_rfoff;
187 u8 reg_pdnmode;
188 u32 rfoff_reason;
189
190
191 u32 cur_ps_level;
192 u32 reg_rfps_level;
193 uint ips_enter_cnts;
194 uint ips_leave_cnts;
195
196 u8 ips_mode;
197 u8 ips_mode_req;
198
199 uint bips_processing;
200 u32 ips_deny_time;
201 u8 ps_processing;
202
203 u8 bLeisurePs;
204 u8 LpsIdleCount;
205 u8 power_mgnt;
206 u8 bFwCurrentInPSMode;
207 u32 DelayLPSLastTimeStamp;
208 u8 btcoex_rfon;
209 s32 pnp_current_pwr_state;
210 u8 pnp_bstop_trx;
211
212 u8 bInternalAutoSuspend;
213 u8 bInSuspend;
214#ifdef CONFIG_BT_COEXIST
215 u8 bAutoResume;
216 u8 autopm_cnt;
217#endif
218 u8 bSupportRemoteWakeup;
219 struct timer_list pwr_state_check_timer;
220 int pwr_state_check_interval;
221 u8 pwr_state_check_cnts;
222
223 int ps_flag;
224
225 enum rt_rf_power_state rf_pwrstate;
226 enum rt_rf_power_state change_rfpwrstate;
227
228 u8 wepkeymask;
229 u8 bHWPowerdown;
230 u8 bHWPwrPindetect;
231 u8 bkeepfwalive;
232 u8 brfoffbyhw;
233 unsigned long PS_BBRegBackup[PSBBREG_TOTALCNT];
234};
235
236#define rtw_get_ips_mode_req(pwrctrlpriv) \
237 (pwrctrlpriv)->ips_mode_req
238
239#define rtw_ips_mode_req(pwrctrlpriv, ips_mode) \
240 ((pwrctrlpriv)->ips_mode_req = (ips_mode))
241
242#define RTW_PWR_STATE_CHK_INTERVAL 2000
243
244#define _rtw_set_pwr_state_check_timer(pwrctrlpriv, ms) \
245 do { \
246 _set_timer(&(pwrctrlpriv)->pwr_state_check_timer, (ms)); \
247 } while (0)
248
249#define rtw_set_pwr_state_check_timer(pwrctrl) \
250 _rtw_set_pwr_state_check_timer((pwrctrl), \
251 (pwrctrl)->pwr_state_check_interval)
252
253void rtw_init_pwrctrl_priv(struct adapter *adapter);
254void rtw_free_pwrctrl_priv(struct adapter *adapter);
255
256void rtw_set_ps_mode(struct adapter *adapter, u8 ps_mode, u8 smart_ps,
257 u8 bcn_ant_mode);
258void rtw_set_rpwm(struct adapter *adapter, u8 val8);
259void LeaveAllPowerSaveMode(struct adapter *adapter);
260void ips_enter(struct adapter *padapter);
261int ips_leave(struct adapter *padapter);
262
263void rtw_ps_processor(struct adapter *padapter);
264
265enum rt_rf_power_state RfOnOffDetect(struct adapter *iadapter);
266
267s32 LPS_RF_ON_check(struct adapter *adapter, u32 delay_ms);
268void LPS_Enter(struct adapter *adapter);
269void LPS_Leave(struct adapter *adapter);
270
271u8 rtw_interface_ps_func(struct adapter *adapter,
272 enum hal_intf_ps_func efunc_id, u8 *val);
273void rtw_set_ips_deny(struct adapter *adapter, u32 ms);
274int _rtw_pwr_wakeup(struct adapter *adapter, u32 ips_defer_ms,
275 const char *caller);
276#define rtw_pwr_wakeup(adapter) \
277 _rtw_pwr_wakeup(adapter, RTW_PWR_STATE_CHK_INTERVAL, __func__)
278#define rtw_pwr_wakeup_ex(adapter, ips_deffer_ms) \
279 _rtw_pwr_wakeup(adapter, ips_deffer_ms, __func__)
280int rtw_pm_set_ips(struct adapter *adapter, u8 mode);
281int rtw_pm_set_lps(struct adapter *adapter, u8 mode);
282
283#endif
284