rtw_pwrctrl.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
  4. *
  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. *
  19. ******************************************************************************/
  20. #ifndef __RTW_PWRCTRL_H_
  21. #define __RTW_PWRCTRL_H_
  22. #define FW_PWR0 0
  23. #define FW_PWR1 1
  24. #define FW_PWR2 2
  25. #define FW_PWR3 3
  26. #define HW_PWR0 7
  27. #define HW_PWR1 6
  28. #define HW_PWR2 2
  29. #define HW_PWR3 0
  30. #define HW_PWR4 8
  31. #define FW_PWRMSK 0x7
  32. #define XMIT_ALIVE BIT(0)
  33. #define RECV_ALIVE BIT(1)
  34. #define CMD_ALIVE BIT(2)
  35. #define EVT_ALIVE BIT(3)
  36. enum Power_Mgnt
  37. {
  38. PS_MODE_ACTIVE = 0 ,
  39. PS_MODE_MIN ,
  40. PS_MODE_MAX ,
  41. PS_MODE_DTIM ,
  42. PS_MODE_VOIP ,
  43. PS_MODE_UAPSD_WMM ,
  44. PS_MODE_UAPSD ,
  45. PS_MODE_IBSS ,
  46. PS_MODE_WWLAN ,
  47. PM_Radio_Off ,
  48. PM_Card_Disable ,
  49. PS_MODE_NUM,
  50. };
  51. #ifdef CONFIG_RTL8723B
  52. #define PS_MODE_SELF_DEFINED PS_MODE_DTIM
  53. #endif //
  54. /*
  55. BIT[2:0] = HW state
  56. BIT[3] = Protocol PS state, 0: register active state , 1: register sleep state
  57. BIT[4] = sub-state
  58. */
  59. #define PS_DPS BIT(0)
  60. #define PS_LCLK (PS_DPS)
  61. #define PS_RF_OFF BIT(1)
  62. #define PS_ALL_ON BIT(2)
  63. #define PS_ST_ACTIVE BIT(3)
  64. #define PS_ISR_ENABLE BIT(4)
  65. #define PS_IMR_ENABLE BIT(5)
  66. #define PS_ACK BIT(6)
  67. #define PS_TOGGLE BIT(7)
  68. #define PS_STATE_MASK (0x0F)
  69. #define PS_STATE_HW_MASK (0x07)
  70. #define PS_SEQ_MASK (0xc0)
  71. #define PS_STATE(x) (PS_STATE_MASK & (x))
  72. #define PS_STATE_HW(x) (PS_STATE_HW_MASK & (x))
  73. #define PS_SEQ(x) (PS_SEQ_MASK & (x))
  74. #define PS_STATE_S0 (PS_DPS)
  75. #define PS_STATE_S1 (PS_LCLK)
  76. #define PS_STATE_S2 (PS_RF_OFF)
  77. #define PS_STATE_S3 (PS_ALL_ON)
  78. #define PS_STATE_S4 ((PS_ST_ACTIVE) | (PS_ALL_ON))
  79. #define PS_IS_RF_ON(x) ((x) & (PS_ALL_ON))
  80. #define PS_IS_ACTIVE(x) ((x) & (PS_ST_ACTIVE))
  81. #define CLR_PS_STATE(x) ((x) = ((x) & (0xF0)))
  82. struct reportpwrstate_parm {
  83. unsigned char mode;
  84. unsigned char state; //the CPWM value
  85. unsigned short rsvd;
  86. };
  87. typedef _sema _pwrlock;
  88. __inline static void _init_pwrlock(_pwrlock *plock)
  89. {
  90. _rtw_init_sema(plock, 1);
  91. }
  92. __inline static void _free_pwrlock(_pwrlock *plock)
  93. {
  94. _rtw_free_sema(plock);
  95. }
  96. __inline static void _enter_pwrlock(_pwrlock *plock)
  97. {
  98. _rtw_down_sema(plock);
  99. }
  100. __inline static void _exit_pwrlock(_pwrlock *plock)
  101. {
  102. _rtw_up_sema(plock);
  103. }
  104. #define LPS_DELAY_TIME 1*HZ // 1 sec
  105. #define EXE_PWR_NONE 0x01
  106. #define EXE_PWR_IPS 0x02
  107. #define EXE_PWR_LPS 0x04
  108. // RF state.
  109. typedef enum _rt_rf_power_state
  110. {
  111. rf_on, // RF is on after RFSleep or RFOff
  112. rf_sleep, // 802.11 Power Save mode
  113. rf_off, // HW/SW Radio OFF or Inactive Power Save
  114. //=====Add the new RF state above this line=====//
  115. rf_max
  116. }rt_rf_power_state;
  117. // RF Off Level for IPS or HW/SW radio off
  118. #define RT_RF_OFF_LEVL_ASPM BIT(0) // PCI ASPM
  119. #define RT_RF_OFF_LEVL_CLK_REQ BIT(1) // PCI clock request
  120. #define RT_RF_OFF_LEVL_PCI_D3 BIT(2) // PCI D3 mode
  121. #define RT_RF_OFF_LEVL_HALT_NIC BIT(3) // NIC halt, re-initialize hw parameters
  122. #define RT_RF_OFF_LEVL_FREE_FW BIT(4) // FW free, re-download the FW
  123. #define RT_RF_OFF_LEVL_FW_32K BIT(5) // FW in 32k
  124. #define RT_RF_PS_LEVEL_ALWAYS_ASPM BIT(6) // Always enable ASPM and Clock Req in initialization.
  125. #define RT_RF_LPS_DISALBE_2R BIT(30) // When LPS is on, disable 2R if no packet is received or transmittd.
  126. #define RT_RF_LPS_LEVEL_ASPM BIT(31) // LPS with ASPM
  127. #define RT_IN_PS_LEVEL(ppsc, _PS_FLAG) ((ppsc->cur_ps_level & _PS_FLAG) ? _TRUE : _FALSE)
  128. #define RT_CLEAR_PS_LEVEL(ppsc, _PS_FLAG) (ppsc->cur_ps_level &= (~(_PS_FLAG)))
  129. #define RT_SET_PS_LEVEL(ppsc, _PS_FLAG) (ppsc->cur_ps_level |= _PS_FLAG)
  130. enum _PS_BBRegBackup_ {
  131. PSBBREG_RF0 = 0,
  132. PSBBREG_RF1,
  133. PSBBREG_RF2,
  134. PSBBREG_AFE0,
  135. PSBBREG_TOTALCNT
  136. };
  137. enum { // for ips_mode
  138. IPS_NONE=0,
  139. IPS_NORMAL,
  140. IPS_LEVEL_2,
  141. };
  142. struct pwrctrl_priv
  143. {
  144. _pwrlock lock;
  145. volatile u8 rpwm; // requested power state for fw
  146. volatile u8 cpwm; // fw current power state. updated when 1. read from HCPWM 2. driver lowers power level
  147. volatile u8 tog; // toggling
  148. volatile u8 cpwm_tog; // toggling
  149. u8 pwr_mode;
  150. u8 smart_ps;
  151. u8 bcn_ant_mode;
  152. u32 alives;
  153. _workitem cpwm_event;
  154. #ifdef CONFIG_LPS_RPWM_TIMER
  155. u8 brpwmtimeout;
  156. _workitem rpwmtimeoutwi;
  157. _timer pwr_rpwm_timer;
  158. #endif // CONFIG_LPS_RPWM_TIMER
  159. u8 bpower_saving;
  160. u8 b_hw_radio_off;
  161. u8 reg_rfoff;
  162. u8 reg_pdnmode; //powerdown mode
  163. u32 rfoff_reason;
  164. //RF OFF Level
  165. u32 cur_ps_level;
  166. u32 reg_rfps_level;
  167. #ifdef CONFIG_PCI_HCI
  168. //just for PCIE ASPM
  169. u8 b_support_aspm; // If it supports ASPM, Offset[560h] = 0x40, otherwise Offset[560h] = 0x00.
  170. u8 b_support_backdoor;
  171. //just for PCIE ASPM
  172. u8 const_amdpci_aspm;
  173. #endif
  174. uint ips_enter_cnts;
  175. uint ips_leave_cnts;
  176. u8 ips_mode;
  177. u8 ips_mode_req; // used to accept the mode setting request, will update to ipsmode later
  178. uint bips_processing;
  179. u32 ips_deny_time; /* will deny IPS when system time is smaller than this */
  180. u8 ps_processing; /* temporarily used to mark whether in rtw_ps_processor */
  181. u8 bLeisurePs;
  182. u8 LpsIdleCount;
  183. u8 power_mgnt;
  184. u8 bFwCurrentInPSMode;
  185. u32 DelayLPSLastTimeStamp;
  186. u8 btcoex_rfon;
  187. s32 pnp_current_pwr_state;
  188. u8 pnp_bstop_trx;
  189. u8 bInternalAutoSuspend;
  190. u8 bInSuspend;
  191. #ifdef CONFIG_BT_COEXIST
  192. u8 bAutoResume;
  193. u8 autopm_cnt;
  194. #endif
  195. u8 bSupportRemoteWakeup;
  196. #ifdef CONFIG_WOWLAN
  197. u8 wowlan_mode;
  198. u8 wowlan_pattern;
  199. u8 wowlan_magic;
  200. u8 wowlan_unicast;
  201. u8 wowlan_pattern_idx;
  202. u8 wowlan_wake_reason;
  203. u32 wowlan_pattern_context[8][5];
  204. #endif // CONFIG_WOWLAN
  205. _timer pwr_state_check_timer;
  206. int pwr_state_check_interval;
  207. u8 pwr_state_check_cnts;
  208. int ps_flag;
  209. rt_rf_power_state rf_pwrstate;//cur power state
  210. //rt_rf_power_state current_rfpwrstate;
  211. rt_rf_power_state change_rfpwrstate;
  212. u8 wepkeymask;
  213. u8 bHWPowerdown;//if support hw power down
  214. u8 bHWPwrPindetect;
  215. u8 bkeepfwalive;
  216. u8 brfoffbyhw;
  217. unsigned long PS_BBRegBackup[PSBBREG_TOTALCNT];
  218. #ifdef CONFIG_RESUME_IN_WORKQUEUE
  219. struct workqueue_struct *rtw_workqueue;
  220. _workitem resume_work;
  221. #endif
  222. #ifdef CONFIG_HAS_EARLYSUSPEND
  223. struct early_suspend early_suspend;
  224. u8 do_late_resume;
  225. #endif //CONFIG_HAS_EARLYSUSPEND
  226. #ifdef CONFIG_ANDROID_POWER
  227. android_early_suspend_t early_suspend;
  228. u8 do_late_resume;
  229. #endif
  230. #ifdef CONFIG_INTEL_PROXIM
  231. u8 stored_power_mgnt;
  232. #endif
  233. };
  234. #define rtw_get_ips_mode_req(pwrctrlpriv) \
  235. (pwrctrlpriv)->ips_mode_req
  236. #define rtw_ips_mode_req(pwrctrlpriv, ips_mode) \
  237. (pwrctrlpriv)->ips_mode_req = (ips_mode)
  238. #define RTW_PWR_STATE_CHK_INTERVAL 2000
  239. #define _rtw_set_pwr_state_check_timer(pwrctrlpriv, ms) \
  240. do { \
  241. /*DBG_871X("%s _rtw_set_pwr_state_check_timer(%p, %d)\n", __FUNCTION__, (pwrctrlpriv), (ms));*/ \
  242. _set_timer(&(pwrctrlpriv)->pwr_state_check_timer, (ms)); \
  243. } while(0)
  244. #define rtw_set_pwr_state_check_timer(pwrctrlpriv) \
  245. _rtw_set_pwr_state_check_timer((pwrctrlpriv), (pwrctrlpriv)->pwr_state_check_interval)
  246. extern void rtw_init_pwrctrl_priv(_adapter *adapter);
  247. extern void rtw_free_pwrctrl_priv(_adapter * adapter);
  248. #ifdef CONFIG_LPS_LCLK
  249. extern s32 rtw_register_tx_alive(PADAPTER padapter);
  250. extern void rtw_unregister_tx_alive(PADAPTER padapter);
  251. extern s32 rtw_register_rx_alive(PADAPTER padapter);
  252. extern void rtw_unregister_rx_alive(PADAPTER padapter);
  253. extern s32 rtw_register_cmd_alive(PADAPTER padapter);
  254. extern void rtw_unregister_cmd_alive(PADAPTER padapter);
  255. extern s32 rtw_register_evt_alive(PADAPTER padapter);
  256. extern void rtw_unregister_evt_alive(PADAPTER padapter);
  257. extern void cpwm_int_hdl(PADAPTER padapter, struct reportpwrstate_parm *preportpwrstate);
  258. extern void LPS_Leave_check(PADAPTER padapter);
  259. #endif
  260. extern void rtw_set_ps_mode(PADAPTER padapter, u8 ps_mode, u8 smart_ps, u8 bcn_ant_mode);
  261. extern void rtw_set_rpwm(_adapter * padapter, u8 val8);
  262. extern void LeaveAllPowerSaveMode(PADAPTER Adapter);
  263. #ifdef CONFIG_IPS
  264. void ips_enter(_adapter * padapter);
  265. int ips_leave(_adapter * padapter);
  266. #endif
  267. void rtw_ps_processor(_adapter*padapter);
  268. #ifdef CONFIG_AUTOSUSPEND
  269. int autoresume_enter(_adapter* padapter);
  270. #endif
  271. #ifdef SUPPORT_HW_RFOFF_DETECTED
  272. rt_rf_power_state RfOnOffDetect(IN PADAPTER pAdapter );
  273. #endif
  274. #ifdef CONFIG_LPS
  275. s32 LPS_RF_ON_check(PADAPTER padapter, u32 delay_ms);
  276. void LPS_Enter(PADAPTER padapter);
  277. void LPS_Leave(PADAPTER padapter);
  278. #endif
  279. #ifdef CONFIG_RESUME_IN_WORKQUEUE
  280. void rtw_resume_in_workqueue(struct pwrctrl_priv *pwrpriv);
  281. #endif //CONFIG_RESUME_IN_WORKQUEUE
  282. #if defined(CONFIG_HAS_EARLYSUSPEND ) || defined(CONFIG_ANDROID_POWER)
  283. bool rtw_is_earlysuspend_registered(struct pwrctrl_priv *pwrpriv);
  284. bool rtw_is_do_late_resume(struct pwrctrl_priv *pwrpriv);
  285. void rtw_set_do_late_resume(struct pwrctrl_priv *pwrpriv, bool enable);
  286. void rtw_register_early_suspend(struct pwrctrl_priv *pwrpriv);
  287. void rtw_unregister_early_suspend(struct pwrctrl_priv *pwrpriv);
  288. #else
  289. #define rtw_is_earlysuspend_registered(pwrpriv) _FALSE
  290. #define rtw_is_do_late_resume(pwrpriv) _FALSE
  291. #define rtw_set_do_late_resume(pwrpriv, enable) do {} while (0)
  292. #define rtw_register_early_suspend(pwrpriv) do {} while (0)
  293. #define rtw_unregister_early_suspend(pwrpriv) do {} while (0)
  294. #endif /* CONFIG_HAS_EARLYSUSPEND || CONFIG_ANDROID_POWER */
  295. u8 rtw_interface_ps_func(_adapter *padapter,HAL_INTF_PS_FUNC efunc_id,u8* val);
  296. void rtw_set_ips_deny(_adapter *padapter, u32 ms);
  297. int _rtw_pwr_wakeup(_adapter *padapter, u32 ips_deffer_ms, const char *caller);
  298. #define rtw_pwr_wakeup(adapter) _rtw_pwr_wakeup(adapter, RTW_PWR_STATE_CHK_INTERVAL, __FUNCTION__)
  299. #define rtw_pwr_wakeup_ex(adapter, ips_deffer_ms) _rtw_pwr_wakeup(adapter, ips_deffer_ms, __FUNCTION__)
  300. int rtw_pm_set_ips(_adapter *padapter, u8 mode);
  301. int rtw_pm_set_lps(_adapter *padapter, u8 mode);
  302. #endif //__RTL871X_PWRCTRL_H_