• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2 /* Copyright(c) 2007 - 2012 Realtek Corporation. */
3 
4 #ifndef __RTW_PWRCTRL_H_
5 #define __RTW_PWRCTRL_H_
6 
7 #include "osdep_service.h"
8 #include "drv_types.h"
9 
10 #define XMIT_ALIVE	BIT(0)
11 #define RECV_ALIVE	BIT(1)
12 #define CMD_ALIVE	BIT(2)
13 #define EVT_ALIVE	BIT(3)
14 
15 enum power_mgnt {
16 	PS_MODE_ACTIVE = 0,
17 	PS_MODE_MIN,
18 	PS_MODE_MAX,
19 	PS_MODE_DTIM,
20 	PS_MODE_VOIP,
21 	PS_MODE_UAPSD_WMM,
22 	PM_Card_Disable,
23 	PS_MODE_NUM
24 };
25 
26 #define LPS_DELAY_TIME	1*HZ /*  1 sec */
27 
28 /*  RF state. */
29 enum rt_rf_power_state {
30 	rf_on,		/*  RF is on after RFSleep or RFOff */
31 	rf_sleep,	/*  802.11 Power Save mode */
32 	rf_off,		/*  HW/SW Radio OFF or Inactive Power Save */
33 	/* Add the new RF state above this line===== */
34 	rf_max
35 };
36 
37 enum { /*  for ips_mode */
38 	IPS_NONE = 0,
39 	IPS_NORMAL,
40 	IPS_LEVEL_2,
41 };
42 
43 struct pwrctrl_priv {
44 	struct mutex lock; /* Mutex used to protect struct pwrctrl_priv */
45 
46 	u8	pwr_mode;
47 	u8	smart_ps;
48 	u8	bcn_ant_mode;
49 
50 	bool	bpower_saving;
51 
52 	uint	ips_enter_cnts;
53 	uint	ips_leave_cnts;
54 
55 	u8	ips_mode;
56 	u8	ips_mode_req;	/*  used to accept the mode setting request,
57 				 *  will update to ipsmode later */
58 	uint bips_processing;
59 	unsigned long ips_deny_time; /* will deny IPS when system time less than this */
60 	u8 ps_processing; /* temp used to mark whether in rtw_ps_processor */
61 
62 	u8	bLeisurePs;
63 	u8	LpsIdleCount;
64 	u8	power_mgnt;
65 	u8	bFwCurrentInPSMode;
66 	u32	DelayLPSLastTimeStamp;
67 
68 	u8		bInSuspend;
69 	u8		bSupportRemoteWakeup;
70 	struct timer_list pwr_state_check_timer;
71 	int		pwr_state_check_interval;
72 
73 	enum rt_rf_power_state	rf_pwrstate;/* cur power state */
74 	enum rt_rf_power_state	change_rfpwrstate;
75 
76 	u8		bkeepfwalive;
77 };
78 
79 #define rtw_get_ips_mode_req(pwrctrlpriv) \
80 	(pwrctrlpriv)->ips_mode_req
81 
82 #define rtw_ips_mode_req(pwrctrlpriv, ips_mode) \
83 	((pwrctrlpriv)->ips_mode_req = (ips_mode))
84 
85 #define RTW_PWR_STATE_CHK_INTERVAL 2000
86 
87 #define _rtw_set_pwr_state_check_timer(pwrctrlpriv, ms) \
88 	do { \
89 		_set_timer(&(pwrctrlpriv)->pwr_state_check_timer, (ms)); \
90 	} while (0)
91 
92 #define rtw_set_pwr_state_check_timer(pwrctrl)			\
93 	_rtw_set_pwr_state_check_timer((pwrctrl),		\
94 				       (pwrctrl)->pwr_state_check_interval)
95 
96 void rtw_init_pwrctrl_priv(struct adapter *adapter);
97 
98 void rtw_set_firmware_ps_mode(struct adapter *adapter, u8 mode);
99 void rtw_set_ps_mode(struct adapter *adapter, u8 ps_mode, u8 smart_ps,
100 		     u8 bcn_ant_mode);
101 void LeaveAllPowerSaveMode(struct adapter *adapter);
102 void ips_enter(struct adapter *padapter);
103 int ips_leave(struct adapter *padapter);
104 
105 void rtw_ps_processor(struct adapter *padapter);
106 
107 void LPS_Enter(struct adapter *adapter);
108 void LPS_Leave(struct adapter *adapter);
109 
110 int rtw_pwr_wakeup(struct adapter *adapter);
111 int rtw_pm_set_ips(struct adapter *adapter, u8 mode);
112 int rtw_pm_set_lps(struct adapter *adapter, u8 mode);
113 
114 #endif  /* __RTL871X_PWRCTRL_H_ */
115