2013-05-08 21:45:39 +00:00
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of version 2 of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
|
|
|
|
*
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
#ifndef __RTW_PWRCTRL_H_
|
|
|
|
#define __RTW_PWRCTRL_H_
|
|
|
|
|
2014-12-11 21:15:04 +00:00
|
|
|
#include <drv_conf.h>
|
2013-05-08 21:45:39 +00:00
|
|
|
#include <osdep_service.h>
|
|
|
|
#include <drv_types.h>
|
|
|
|
|
2014-12-11 21:15:04 +00:00
|
|
|
#ifdef CONFIG_HAS_EARLYSUSPEND
|
|
|
|
#include <linux/earlysuspend.h>
|
2015-03-16 14:43:53 +00:00
|
|
|
#endif /* CONFIG_HAS_EARLYSUSPEND */
|
2014-12-11 21:15:04 +00:00
|
|
|
|
|
|
|
|
2014-12-19 06:59:46 +00:00
|
|
|
#define FW_PWR0 0
|
|
|
|
#define FW_PWR1 1
|
|
|
|
#define FW_PWR2 2
|
|
|
|
#define FW_PWR3 3
|
2014-12-11 21:15:04 +00:00
|
|
|
|
|
|
|
|
2014-12-19 06:59:46 +00:00
|
|
|
#define HW_PWR0 7
|
|
|
|
#define HW_PWR1 6
|
|
|
|
#define HW_PWR2 2
|
2014-12-11 21:15:04 +00:00
|
|
|
#define HW_PWR3 0
|
|
|
|
#define HW_PWR4 8
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
#define FW_PWRMSK 0x7
|
|
|
|
|
2014-12-11 21:15:04 +00:00
|
|
|
|
2013-05-08 21:45:39 +00:00
|
|
|
#define XMIT_ALIVE BIT(0)
|
|
|
|
#define RECV_ALIVE BIT(1)
|
|
|
|
#define CMD_ALIVE BIT(2)
|
|
|
|
#define EVT_ALIVE BIT(3)
|
|
|
|
|
2014-12-11 21:15:04 +00:00
|
|
|
|
|
|
|
enum Power_Mgnt
|
|
|
|
{
|
|
|
|
PS_MODE_ACTIVE = 0 ,
|
|
|
|
PS_MODE_MIN ,
|
|
|
|
PS_MODE_MAX ,
|
|
|
|
PS_MODE_DTIM ,
|
|
|
|
PS_MODE_VOIP ,
|
|
|
|
PS_MODE_UAPSD_WMM ,
|
|
|
|
PS_MODE_UAPSD ,
|
|
|
|
PS_MODE_IBSS ,
|
|
|
|
PS_MODE_WWLAN ,
|
|
|
|
PM_Radio_Off ,
|
|
|
|
PM_Card_Disable ,
|
2013-05-08 21:45:39 +00:00
|
|
|
PS_MODE_NUM
|
|
|
|
};
|
|
|
|
|
2014-12-11 21:15:04 +00:00
|
|
|
|
2013-05-08 21:45:39 +00:00
|
|
|
/*
|
|
|
|
BIT[2:0] = HW state
|
2014-12-11 21:15:04 +00:00
|
|
|
BIT[3] = Protocol PS state, 0: register active state , 1: register sleep state
|
2013-05-08 21:45:39 +00:00
|
|
|
BIT[4] = sub-state
|
|
|
|
*/
|
|
|
|
|
2014-12-11 21:15:04 +00:00
|
|
|
#define PS_DPS BIT(0)
|
|
|
|
#define PS_LCLK (PS_DPS)
|
|
|
|
#define PS_RF_OFF BIT(1)
|
|
|
|
#define PS_ALL_ON BIT(2)
|
2013-05-08 21:45:39 +00:00
|
|
|
#define PS_ST_ACTIVE BIT(3)
|
|
|
|
|
|
|
|
#define PS_ISR_ENABLE BIT(4)
|
|
|
|
#define PS_IMR_ENABLE BIT(5)
|
2014-12-11 21:15:04 +00:00
|
|
|
#define PS_ACK BIT(6)
|
|
|
|
#define PS_TOGGLE BIT(7)
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
#define PS_STATE_MASK (0x0F)
|
|
|
|
#define PS_STATE_HW_MASK (0x07)
|
2014-12-11 21:15:04 +00:00
|
|
|
#define PS_SEQ_MASK (0xc0)
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
#define PS_STATE(x) (PS_STATE_MASK & (x))
|
2014-12-11 21:15:04 +00:00
|
|
|
#define PS_STATE_HW(x) (PS_STATE_HW_MASK & (x))
|
2013-05-08 21:45:39 +00:00
|
|
|
#define PS_SEQ(x) (PS_SEQ_MASK & (x))
|
|
|
|
|
|
|
|
#define PS_STATE_S0 (PS_DPS)
|
|
|
|
#define PS_STATE_S1 (PS_LCLK)
|
|
|
|
#define PS_STATE_S2 (PS_RF_OFF)
|
|
|
|
#define PS_STATE_S3 (PS_ALL_ON)
|
|
|
|
#define PS_STATE_S4 ((PS_ST_ACTIVE) | (PS_ALL_ON))
|
|
|
|
|
2014-12-11 21:15:04 +00:00
|
|
|
|
2013-05-08 21:45:39 +00:00
|
|
|
#define PS_IS_RF_ON(x) ((x) & (PS_ALL_ON))
|
|
|
|
#define PS_IS_ACTIVE(x) ((x) & (PS_ST_ACTIVE))
|
|
|
|
#define CLR_PS_STATE(x) ((x) = ((x) & (0xF0)))
|
|
|
|
|
2014-12-11 21:15:04 +00:00
|
|
|
|
2013-05-08 21:45:39 +00:00
|
|
|
struct reportpwrstate_parm {
|
|
|
|
unsigned char mode;
|
2015-03-16 14:43:53 +00:00
|
|
|
unsigned char state; /* the CPWM value */
|
2013-05-08 21:45:39 +00:00
|
|
|
unsigned short rsvd;
|
2014-12-19 06:59:46 +00:00
|
|
|
};
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2015-03-16 13:54:18 +00:00
|
|
|
__inline static void _init_pwrlock(struct semaphore *plock)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
_rtw_init_sema(plock, 1);
|
|
|
|
}
|
|
|
|
|
2015-03-16 13:54:18 +00:00
|
|
|
__inline static void _free_pwrlock(struct semaphore *plock)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
_rtw_free_sema(plock);
|
|
|
|
}
|
|
|
|
|
2014-12-11 21:15:04 +00:00
|
|
|
|
2015-03-16 13:54:18 +00:00
|
|
|
__inline static void _enter_pwrlock(struct semaphore *plock)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
_rtw_down_sema(plock);
|
|
|
|
}
|
|
|
|
|
2014-12-11 21:15:04 +00:00
|
|
|
|
2015-03-16 13:54:18 +00:00
|
|
|
__inline static void _exit_pwrlock(struct semaphore *plock)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
_rtw_up_sema(plock);
|
|
|
|
}
|
|
|
|
|
2015-03-16 14:43:53 +00:00
|
|
|
#define LPS_DELAY_TIME 1*HZ /* 1 sec */
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
#define EXE_PWR_NONE 0x01
|
|
|
|
#define EXE_PWR_IPS 0x02
|
|
|
|
#define EXE_PWR_LPS 0x04
|
|
|
|
|
2015-03-16 14:43:53 +00:00
|
|
|
/* RF state. */
|
2014-12-11 21:15:04 +00:00
|
|
|
typedef enum _rt_rf_power_state
|
|
|
|
{
|
2015-03-16 14:43:53 +00:00
|
|
|
rf_on, /* RF is on after RFSleep or RFOff */
|
|
|
|
rf_sleep, /* 802.11 Power Save mode */
|
|
|
|
rf_off, /* HW/SW Radio OFF or Inactive Power Save */
|
|
|
|
/* Add the new RF state above this line===== */
|
2013-05-08 21:45:39 +00:00
|
|
|
rf_max
|
2014-12-11 21:15:04 +00:00
|
|
|
}rt_rf_power_state;
|
|
|
|
|
2015-03-16 14:43:53 +00:00
|
|
|
/* RF Off Level for IPS or HW/SW radio off */
|
|
|
|
#define RT_RF_OFF_LEVL_ASPM BIT(0) /* PCI ASPM */
|
|
|
|
#define RT_RF_OFF_LEVL_CLK_REQ BIT(1) /* PCI clock request */
|
|
|
|
#define RT_RF_OFF_LEVL_PCI_D3 BIT(2) /* PCI D3 mode */
|
|
|
|
#define RT_RF_OFF_LEVL_HALT_NIC BIT(3) /* NIC halt, re-initialize hw parameters */
|
|
|
|
#define RT_RF_OFF_LEVL_FREE_FW BIT(4) /* FW free, re-download the FW */
|
|
|
|
#define RT_RF_OFF_LEVL_FW_32K BIT(5) /* FW in 32k */
|
|
|
|
#define RT_RF_PS_LEVEL_ALWAYS_ASPM BIT(6) /* Always enable ASPM and Clock Req in initialization. */
|
|
|
|
#define RT_RF_LPS_DISALBE_2R BIT(30) /* When LPS is on, disable 2R if no packet is received or transmittd. */
|
|
|
|
#define RT_RF_LPS_LEVEL_ASPM BIT(31) /* LPS with ASPM */
|
2014-12-11 21:15:04 +00:00
|
|
|
|
2014-12-29 02:13:24 +00:00
|
|
|
#define RT_IN_PS_LEVEL(ppsc, _PS_FLAG) ((ppsc->cur_ps_level & _PS_FLAG) ? true : false)
|
2014-12-11 21:15:04 +00:00
|
|
|
#define RT_CLEAR_PS_LEVEL(ppsc, _PS_FLAG) (ppsc->cur_ps_level &= (~(_PS_FLAG)))
|
|
|
|
#define RT_SET_PS_LEVEL(ppsc, _PS_FLAG) (ppsc->cur_ps_level |= _PS_FLAG)
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
enum _PS_BBRegBackup_ {
|
|
|
|
PSBBREG_RF0 = 0,
|
|
|
|
PSBBREG_RF1,
|
|
|
|
PSBBREG_RF2,
|
|
|
|
PSBBREG_AFE0,
|
|
|
|
PSBBREG_TOTALCNT
|
|
|
|
};
|
|
|
|
|
2015-03-16 14:43:53 +00:00
|
|
|
enum { /* for ips_mode */
|
2014-12-11 21:15:04 +00:00
|
|
|
IPS_NONE=0,
|
2013-05-08 21:45:39 +00:00
|
|
|
IPS_NORMAL,
|
2014-12-19 06:59:46 +00:00
|
|
|
IPS_LEVEL_2,
|
2013-05-08 21:45:39 +00:00
|
|
|
};
|
|
|
|
|
2014-12-11 21:15:04 +00:00
|
|
|
struct pwrctrl_priv
|
|
|
|
{
|
2015-03-16 13:54:18 +00:00
|
|
|
struct semaphore lock;
|
2015-03-16 14:43:53 +00:00
|
|
|
volatile u8 rpwm; /* requested power state for fw */
|
|
|
|
volatile u8 cpwm; /* fw current power state. updated when 1. read from HCPWM 2. driver lowers power level */
|
|
|
|
volatile u8 tog; /* toggling */
|
|
|
|
volatile u8 cpwm_tog; /* toggling */
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
u8 pwr_mode;
|
|
|
|
u8 smart_ps;
|
|
|
|
u8 bcn_ant_mode;
|
|
|
|
|
|
|
|
u32 alives;
|
2015-03-16 13:54:18 +00:00
|
|
|
struct work_struct cpwm_event;
|
2013-05-08 21:45:39 +00:00
|
|
|
u8 bpower_saving;
|
|
|
|
|
|
|
|
u8 b_hw_radio_off;
|
|
|
|
u8 reg_rfoff;
|
2015-03-16 14:43:53 +00:00
|
|
|
u8 reg_pdnmode; /* powerdown mode */
|
2013-05-08 21:45:39 +00:00
|
|
|
u32 rfoff_reason;
|
|
|
|
|
2015-03-16 14:43:53 +00:00
|
|
|
/* RF OFF Level */
|
2013-05-08 21:45:39 +00:00
|
|
|
u32 cur_ps_level;
|
|
|
|
u32 reg_rfps_level;
|
|
|
|
|
2014-12-19 06:59:46 +00:00
|
|
|
uint ips_enter_cnts;
|
|
|
|
uint ips_leave_cnts;
|
2014-12-11 21:15:04 +00:00
|
|
|
|
2014-12-19 06:59:46 +00:00
|
|
|
u8 ips_mode;
|
2015-03-16 14:43:53 +00:00
|
|
|
u8 ips_mode_req; /* used to accept the mode setting request, will update to ipsmode later */
|
2013-05-08 21:45:39 +00:00
|
|
|
uint bips_processing;
|
2014-12-11 21:15:04 +00:00
|
|
|
u32 ips_deny_time; /* will deny IPS when system time is smaller than this */
|
|
|
|
u8 ps_processing; /* temporarily used to mark whether in rtw_ps_processor */
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
u8 bLeisurePs;
|
|
|
|
u8 LpsIdleCount;
|
|
|
|
u8 power_mgnt;
|
|
|
|
u8 bFwCurrentInPSMode;
|
|
|
|
u32 DelayLPSLastTimeStamp;
|
2014-12-19 06:59:46 +00:00
|
|
|
u8 btcoex_rfon;
|
2013-05-08 21:45:39 +00:00
|
|
|
s32 pnp_current_pwr_state;
|
|
|
|
u8 pnp_bstop_trx;
|
|
|
|
|
2014-12-11 21:15:04 +00:00
|
|
|
|
2013-05-08 21:45:39 +00:00
|
|
|
u8 bInternalAutoSuspend;
|
|
|
|
u8 bInSuspend;
|
|
|
|
#ifdef CONFIG_BT_COEXIST
|
|
|
|
u8 bAutoResume;
|
|
|
|
u8 autopm_cnt;
|
|
|
|
#endif
|
2014-12-19 06:59:46 +00:00
|
|
|
u8 bSupportRemoteWakeup;
|
2015-03-16 13:54:18 +00:00
|
|
|
struct timer_list pwr_state_check_timer;
|
2013-05-08 21:45:39 +00:00
|
|
|
int pwr_state_check_interval;
|
|
|
|
u8 pwr_state_check_cnts;
|
|
|
|
|
2014-12-19 06:59:46 +00:00
|
|
|
int ps_flag;
|
|
|
|
|
2015-03-16 14:43:53 +00:00
|
|
|
rt_rf_power_state rf_pwrstate;/* cur power state */
|
|
|
|
/* rt_rf_power_state current_rfpwrstate; */
|
2014-12-11 21:15:04 +00:00
|
|
|
rt_rf_power_state change_rfpwrstate;
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2015-03-16 14:43:53 +00:00
|
|
|
u8 bHWPowerdown;/* if support hw power down */
|
2013-05-08 21:45:39 +00:00
|
|
|
u8 bHWPwrPindetect;
|
2014-12-19 06:59:46 +00:00
|
|
|
u8 bkeepfwalive;
|
2013-05-08 21:45:39 +00:00
|
|
|
u8 brfoffbyhw;
|
|
|
|
unsigned long PS_BBRegBackup[PSBBREG_TOTALCNT];
|
2014-12-11 21:15:04 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_HAS_EARLYSUSPEND
|
|
|
|
struct early_suspend early_suspend;
|
|
|
|
u8 do_late_resume;
|
2015-03-16 14:43:53 +00:00
|
|
|
#endif /* CONFIG_HAS_EARLYSUSPEND */
|
2014-12-19 06:59:46 +00:00
|
|
|
|
2014-12-11 21:15:04 +00:00
|
|
|
#ifdef CONFIG_ANDROID_POWER
|
|
|
|
android_early_suspend_t early_suspend;
|
|
|
|
u8 do_late_resume;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_INTEL_PROXIM
|
|
|
|
u8 stored_power_mgnt;
|
|
|
|
#endif
|
2013-05-08 21:45:39 +00:00
|
|
|
};
|
|
|
|
|
2014-12-11 21:15:04 +00:00
|
|
|
#define rtw_get_ips_mode_req(pwrctl) \
|
|
|
|
(pwrctl)->ips_mode_req
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2014-12-11 21:15:04 +00:00
|
|
|
#define rtw_ips_mode_req(pwrctl, ips_mode) \
|
|
|
|
(pwrctl)->ips_mode_req = (ips_mode)
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
#define RTW_PWR_STATE_CHK_INTERVAL 2000
|
|
|
|
|
2014-12-11 21:15:04 +00:00
|
|
|
#define _rtw_set_pwr_state_check_timer(pwrctl, ms) \
|
2013-05-08 21:45:39 +00:00
|
|
|
do { \
|
2014-12-11 21:15:04 +00:00
|
|
|
_set_timer(&(pwrctl)->pwr_state_check_timer, (ms)); \
|
2015-08-15 18:04:12 +00:00
|
|
|
} while (0)
|
2014-12-19 06:59:46 +00:00
|
|
|
|
2014-12-11 21:15:04 +00:00
|
|
|
#define rtw_set_pwr_state_check_timer(pwrctl) \
|
|
|
|
_rtw_set_pwr_state_check_timer((pwrctl), (pwrctl)->pwr_state_check_interval)
|
|
|
|
|
2015-02-25 02:22:38 +00:00
|
|
|
void rtw_init_pwrctrl_priv(struct adapter *adapter);
|
|
|
|
void rtw_free_pwrctrl_priv(struct adapter * adapter);
|
2014-12-11 21:15:04 +00:00
|
|
|
|
2015-02-24 16:18:56 +00:00
|
|
|
void rtw_set_ps_mode(struct adapter *padapter, u8 ps_mode, u8 smart_ps, u8 bcn_ant_mode);
|
|
|
|
void rtw_set_rpwm(struct adapter * padapter, u8 val8);
|
|
|
|
void LeaveAllPowerSaveMode(struct adapter *Adapter);
|
2014-12-17 23:13:53 +00:00
|
|
|
void _ips_enter(struct adapter * padapter);
|
|
|
|
void ips_enter(struct adapter * padapter);
|
|
|
|
int _ips_leave(struct adapter * padapter);
|
|
|
|
int ips_leave(struct adapter * padapter);
|
2014-12-11 21:15:04 +00:00
|
|
|
|
2014-12-17 23:13:53 +00:00
|
|
|
void rtw_ps_processor(struct adapter*padapter);
|
2014-12-11 21:15:04 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_AUTOSUSPEND
|
2014-12-17 23:13:53 +00:00
|
|
|
int autoresume_enter(struct adapter* padapter);
|
2014-12-11 21:15:04 +00:00
|
|
|
#endif
|
2015-03-13 17:06:38 +00:00
|
|
|
rt_rf_power_state RfOnOffDetect(struct adapter *pAdapter );
|
2014-12-11 21:15:04 +00:00
|
|
|
|
2014-12-17 23:13:53 +00:00
|
|
|
s32 LPS_RF_ON_check(struct adapter *padapter, u32 delay_ms);
|
|
|
|
void LPS_Enter(struct adapter *padapter);
|
|
|
|
void LPS_Leave(struct adapter *padapter);
|
2014-12-11 21:15:04 +00:00
|
|
|
|
|
|
|
#if defined(CONFIG_HAS_EARLYSUSPEND ) || defined(CONFIG_ANDROID_POWER)
|
|
|
|
bool rtw_is_earlysuspend_registered(struct pwrctrl_priv *pwrpriv);
|
|
|
|
bool rtw_is_do_late_resume(struct pwrctrl_priv *pwrpriv);
|
|
|
|
void rtw_set_do_late_resume(struct pwrctrl_priv *pwrpriv, bool enable);
|
|
|
|
void rtw_register_early_suspend(struct pwrctrl_priv *pwrpriv);
|
|
|
|
void rtw_unregister_early_suspend(struct pwrctrl_priv *pwrpriv);
|
|
|
|
#else
|
2014-12-29 02:13:24 +00:00
|
|
|
#define rtw_is_earlysuspend_registered(pwrpriv) false
|
|
|
|
#define rtw_is_do_late_resume(pwrpriv) false
|
2014-12-11 21:15:04 +00:00
|
|
|
#define rtw_set_do_late_resume(pwrpriv, enable) do {} while (0)
|
|
|
|
#define rtw_register_early_suspend(pwrpriv) do {} while (0)
|
|
|
|
#define rtw_unregister_early_suspend(pwrpriv) do {} while (0)
|
|
|
|
#endif /* CONFIG_HAS_EARLYSUSPEND || CONFIG_ANDROID_POWER */
|
|
|
|
|
2015-03-17 15:31:25 +00:00
|
|
|
u8 rtw_interface_ps_func(struct adapter *padapter, enum HAL_INTF_PS_FUNC efunc_id,u8* val);
|
2014-12-17 23:13:53 +00:00
|
|
|
void rtw_set_ips_deny(struct adapter *padapter, u32 ms);
|
|
|
|
int _rtw_pwr_wakeup(struct adapter *padapter, u32 ips_deffer_ms, const char *caller);
|
2014-12-11 21:15:04 +00:00
|
|
|
#define rtw_pwr_wakeup(adapter) _rtw_pwr_wakeup(adapter, RTW_PWR_STATE_CHK_INTERVAL, __FUNCTION__)
|
|
|
|
#define rtw_pwr_wakeup_ex(adapter, ips_deffer_ms) _rtw_pwr_wakeup(adapter, ips_deffer_ms, __FUNCTION__)
|
2014-12-17 23:13:53 +00:00
|
|
|
int rtw_pm_set_ips(struct adapter *padapter, u8 mode);
|
|
|
|
int rtw_pm_set_lps(struct adapter *padapter, u8 mode);
|
2014-12-11 21:15:04 +00:00
|
|
|
|
2015-03-16 14:43:53 +00:00
|
|
|
#endif /* __RTL871X_PWRCTRL_H_ */
|