blob: 6024c4f63d5bd64179afab9a81da69801c3fa51b [file] [log] [blame]
Ali Bahar0e54f602011-08-23 13:53:37 +08001/******************************************************************************
2 *
3 * Copyright(c) 2007 - 2010 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 *
Ali Baharb4f62092011-08-23 13:53:38 +080018 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 *
21 * Contact information:
22 * WLAN FAE <wlanfae@realtek.com>
23 * Larry Finger <Larry.Finger@lwfinger.net>
Ali Bahar0e54f602011-08-23 13:53:37 +080024 *
25 ******************************************************************************/
Larry Finger2865d422010-08-20 10:15:30 -050026#ifndef __RTL871X_PWRCTRL_H_
27#define __RTL871X_PWRCTRL_H_
28
29#include "osdep_service.h"
30#include "drv_types.h"
31
32
33#define FW_PWR0 0
34#define FW_PWR1 1
35#define FW_PWR2 2
36#define FW_PWR3 3
37
38
39#define HW_PWR0 7
40#define HW_PWR1 6
41#define HW_PWR2 2
42#define HW_PWR3 0
43#define HW_PWR4 8
44
45#define FW_PWRMSK 0x7
46
47
48#define XMIT_ALIVE BIT(0)
49#define RECV_ALIVE BIT(1)
50#define CMD_ALIVE BIT(2)
51#define EVT_ALIVE BIT(3)
52
53
54enum Power_Mgnt {
55 PS_MODE_ACTIVE = 0 ,
56 PS_MODE_MIN ,
57 PS_MODE_MAX ,
58 PS_MODE_DTIM ,
59 PS_MODE_VOIP ,
60 PS_MODE_UAPSD_WMM ,
61 PS_MODE_UAPSD ,
62 PS_MODE_IBSS ,
63 PS_MODE_WWLAN ,
64 PM_Radio_Off ,
65 PM_Card_Disable ,
66 PS_MODE_NUM
67};
68
69
70/*
71 BIT[2:0] = HW state
72 BIT[3] = Protocol PS state, 0: register active state,
73 1: register sleep state
74 BIT[4] = sub-state
75*/
76
77#define PS_DPS BIT(0)
78#define PS_LCLK (PS_DPS)
79#define PS_RF_OFF BIT(1)
80#define PS_ALL_ON BIT(2)
81#define PS_ST_ACTIVE BIT(3)
82#define PS_LP BIT(4) /* low performance */
83
84#define PS_STATE_MASK (0x0F)
85#define PS_STATE_HW_MASK (0x07)
86#define PS_SEQ_MASK (0xc0)
87
88#define PS_STATE(x) (PS_STATE_MASK & (x))
89#define PS_STATE_HW(x) (PS_STATE_HW_MASK & (x))
90#define PS_SEQ(x) (PS_SEQ_MASK & (x))
91
92#define PS_STATE_S0 (PS_DPS)
93#define PS_STATE_S1 (PS_LCLK)
94#define PS_STATE_S2 (PS_RF_OFF)
95#define PS_STATE_S3 (PS_ALL_ON)
96#define PS_STATE_S4 ((PS_ST_ACTIVE) | (PS_ALL_ON))
97
98
99#define PS_IS_RF_ON(x) ((x) & (PS_ALL_ON))
100#define PS_IS_ACTIVE(x) ((x) & (PS_ST_ACTIVE))
101#define CLR_PS_STATE(x) ((x) = ((x) & (0xF0)))
102
103
104struct reportpwrstate_parm {
105 unsigned char mode;
106 unsigned char state; /* the CPWM value */
107 unsigned short rsvd;
108};
109
110static inline void _enter_pwrlock(struct semaphore *plock)
111{
112 _down_sema(plock);
113}
114
115struct pwrctrl_priv {
116 struct semaphore lock;
117 /*volatile*/ u8 rpwm; /* requested power state for fw */
118 /* fw current power state. updated when 1. read from HCPWM or
119 * 2. driver lowers power level */
120 /*volatile*/ u8 cpwm;
121 /*volatile*/ u8 tog; /* toggling */
122 /*volatile*/ u8 cpwm_tog; /* toggling */
123 /*volatile*/ u8 tgt_rpwm; /* wanted power state */
124 uint pwr_mode;
125 uint smart_ps;
126 uint alives;
127 uint ImrContent; /* used to store original imr. */
128 uint bSleep; /* sleep -> active is different from active -> sleep. */
129
130 _workitem SetPSModeWorkItem;
131 _workitem rpwm_workitem;
132 struct timer_list rpwm_check_timer;
133 u8 rpwm_retry;
134 uint bSetPSModeWorkItemInProgress;
135
Larry Finger2865d422010-08-20 10:15:30 -0500136 spinlock_t pnp_pwr_mgnt_lock;
137 s32 pnp_current_pwr_state;
138 u8 pnp_bstop_trx;
139 u8 pnp_wwirp_pending;
140};
141
142void r8712_init_pwrctrl_priv(struct _adapter *adapter);
143sint r8712_register_cmd_alive(struct _adapter *padapter);
144void r8712_unregister_cmd_alive(struct _adapter *padapter);
145void r8712_cpwm_int_hdl(struct _adapter *padapter,
146 struct reportpwrstate_parm *preportpwrstate);
147void r8712_set_ps_mode(struct _adapter *padapter, uint ps_mode,
148 uint smart_ps);
149void r8712_set_rpwm(struct _adapter *padapter, u8 val8);
150
151#endif /* __RTL871X_PWRCTRL_H_ */