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