1 /******************************************************************************
3 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
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.
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
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
19 ******************************************************************************/
20 #ifndef __RTW_PWRCTRL_H_
21 #define __RTW_PWRCTRL_H_
23 #include <osdep_service.h>
24 #include <drv_types.h>
38 #define XMIT_ALIVE BIT(0)
39 #define RECV_ALIVE BIT(1)
40 #define CMD_ALIVE BIT(2)
41 #define EVT_ALIVE BIT(3)
60 BIT[3] = Protocol PS state, 0: register active state,
61 1: register sleep state
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)
71 #define PS_ISR_ENABLE BIT(4)
72 #define PS_IMR_ENABLE BIT(5)
74 #define PS_TOGGLE BIT(7)
76 #define PS_STATE_MASK (0x0F)
77 #define PS_STATE_HW_MASK (0x07)
78 #define PS_SEQ_MASK (0xc0)
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))
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))
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)))
94 struct reportpwrstate_parm {
96 unsigned char state; /* the CPWM value */
100 static inline void _init_pwrlock(struct semaphore *plock)
102 _rtw_init_sema(plock, 1);
105 static inline void _free_pwrlock(struct semaphore *plock)
107 _rtw_free_sema(plock);
110 static inline void _enter_pwrlock(struct semaphore *plock)
112 _rtw_down_sema(plock);
115 static inline void _exit_pwrlock(struct semaphore *plock)
120 #define LPS_DELAY_TIME 1*HZ /* 1 sec */
122 #define EXE_PWR_NONE 0x01
123 #define EXE_PWR_IPS 0x02
124 #define EXE_PWR_LPS 0x04
127 enum rt_rf_power_state {
128 rf_on, /* RF is on after RFSleep or RFOff */
129 rf_sleep, /* 802.11 Power Save mode */
130 rf_off, /* HW/SW Radio OFF or Inactive Power Save */
131 /* Add the new RF state above this line===== */
135 /* RF Off Level for IPS or HW/SW radio off */
136 #define RT_RF_OFF_LEVL_ASPM BIT(0) /* PCI ASPM */
137 #define RT_RF_OFF_LEVL_CLK_REQ BIT(1) /* PCI clock request */
138 #define RT_RF_OFF_LEVL_PCI_D3 BIT(2) /* PCI D3 mode */
139 #define RT_RF_OFF_LEVL_HALT_NIC BIT(3) /* NIC halt, re-init hw param*/
140 #define RT_RF_OFF_LEVL_FREE_FW BIT(4) /* FW free, re-download the FW*/
141 #define RT_RF_OFF_LEVL_FW_32K BIT(5) /* FW in 32k */
142 #define RT_RF_PS_LEVEL_ALWAYS_ASPM BIT(6) /* Always enable ASPM and Clock
143 * Req in initialization. */
144 #define RT_RF_LPS_DISALBE_2R BIT(30) /* When LPS is on, disable 2R
145 * if no packet is RX or TX. */
146 #define RT_RF_LPS_LEVEL_ASPM BIT(31) /* LPS with ASPM */
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)
155 enum _PS_BBRegBackup_ {
163 enum { /* for ips_mode */
169 struct pwrctrl_priv {
170 struct semaphore lock;
171 volatile u8 rpwm; /* requested power state for fw */
172 volatile u8 cpwm; /* fw current power state. updated when
173 * 1. read from HCPWM 2. driver lowers power level */
174 volatile u8 tog; /* toggling */
175 volatile u8 cpwm_tog; /* toggling */
182 struct work_struct cpwm_event;
187 u8 reg_pdnmode; /* powerdown mode */
197 u8 ips_mode_req; /* used to accept the mode setting request,
198 * will update to ipsmode later */
199 uint bips_processing;
200 u32 ips_deny_time; /* will deny IPS when system time less than this */
201 u8 ps_processing; /* temp used to mark whether in rtw_ps_processor */
206 u8 bFwCurrentInPSMode;
207 u32 DelayLPSLastTimeStamp;
209 s32 pnp_current_pwr_state;
212 u8 bInternalAutoSuspend;
214 #ifdef CONFIG_BT_COEXIST
218 u8 bSupportRemoteWakeup;
219 struct timer_list pwr_state_check_timer;
220 int pwr_state_check_interval;
221 u8 pwr_state_check_cnts;
225 enum rt_rf_power_state rf_pwrstate;/* cur power state */
226 enum rt_rf_power_state change_rfpwrstate;
229 u8 bHWPowerdown;/* if support hw power down */
233 unsigned long PS_BBRegBackup[PSBBREG_TOTALCNT];
236 #define rtw_get_ips_mode_req(pwrctrlpriv) \
237 (pwrctrlpriv)->ips_mode_req
239 #define rtw_ips_mode_req(pwrctrlpriv, ips_mode) \
240 ((pwrctrlpriv)->ips_mode_req = (ips_mode))
242 #define RTW_PWR_STATE_CHK_INTERVAL 2000
244 #define _rtw_set_pwr_state_check_timer(pwrctrlpriv, ms) \
246 _set_timer(&(pwrctrlpriv)->pwr_state_check_timer, (ms)); \
249 #define rtw_set_pwr_state_check_timer(pwrctrl) \
250 _rtw_set_pwr_state_check_timer((pwrctrl), \
251 (pwrctrl)->pwr_state_check_interval)
253 void rtw_init_pwrctrl_priv(struct adapter *adapter);
254 void rtw_free_pwrctrl_priv(struct adapter *adapter);
256 void rtw_set_ps_mode(struct adapter *adapter, u8 ps_mode, u8 smart_ps,
258 void rtw_set_rpwm(struct adapter *adapter, u8 val8);
259 void LeaveAllPowerSaveMode(struct adapter *adapter);
260 void ips_enter(struct adapter *padapter);
261 int ips_leave(struct adapter *padapter);
263 void rtw_ps_processor(struct adapter *padapter);
265 enum rt_rf_power_state RfOnOffDetect(struct adapter *iadapter);
267 s32 LPS_RF_ON_check(struct adapter *adapter, u32 delay_ms);
268 void LPS_Enter(struct adapter *adapter);
269 void LPS_Leave(struct adapter *adapter);
271 u8 rtw_interface_ps_func(struct adapter *adapter,
272 enum hal_intf_ps_func efunc_id, u8 *val);
273 void rtw_set_ips_deny(struct adapter *adapter, u32 ms);
274 int _rtw_pwr_wakeup(struct adapter *adapter, u32 ips_defer_ms,
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__)
280 int rtw_pm_set_ips(struct adapter *adapter, u8 mode);
281 int rtw_pm_set_lps(struct adapter *adapter, u8 mode);
283 #endif /* __RTL871X_PWRCTRL_H_ */