• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3  * All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  *
20  * File: power.c
21  *
22  * Purpose: Handles 802.11 power management functions
23  *
24  * Author: Lyndon Chen
25  *
26  * Date: July 17, 2002
27  *
28  * Functions:
29  *      vnt_enable_power_saving - Enable Power Saving Mode
30  *      PSvDiasblePowerSaving - Disable Power Saving Mode
31  *      vnt_next_tbtt_wakeup - Decide if we need to wake up at next Beacon
32  *
33  * Revision History:
34  *
35  */
36 
37 #include "mac.h"
38 #include "device.h"
39 #include "power.h"
40 #include "wcmd.h"
41 #include "rxtx.h"
42 #include "card.h"
43 #include "usbpipe.h"
44 
45 /*
46  *
47  * Routine Description:
48  * Enable hw power saving functions
49  *
50  * Return Value:
51  *    None.
52  *
53  */
54 
vnt_enable_power_saving(struct vnt_private * priv,u16 listen_interval)55 void vnt_enable_power_saving(struct vnt_private *priv, u16 listen_interval)
56 {
57 	u16 aid = priv->current_aid | BIT(14) | BIT(15);
58 
59 	/* set period of power up before TBTT */
60 	vnt_mac_write_word(priv, MAC_REG_PWBT, C_PWBT);
61 
62 	if (priv->op_mode != NL80211_IFTYPE_ADHOC) {
63 		/* set AID */
64 		vnt_mac_write_word(priv, MAC_REG_AIDATIM, aid);
65 	}
66 
67 	/* Warren:06-18-2004,the sequence must follow
68 	 * PSEN->AUTOSLEEP->GO2DOZE
69 	 */
70 	/* enable power saving hw function */
71 	vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_PSEN);
72 
73 	/* Set AutoSleep */
74 	vnt_mac_reg_bits_on(priv, MAC_REG_PSCFG, PSCFG_AUTOSLEEP);
75 
76 	/* Warren:MUST turn on this once before turn on AUTOSLEEP ,or the
77 	 * AUTOSLEEP doesn't work
78 	 */
79 	vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_GO2DOZE);
80 
81 	if (listen_interval >= 2) {
82 
83 		/* clear always listen beacon */
84 		vnt_mac_reg_bits_off(priv, MAC_REG_PSCTL, PSCTL_ALBCN);
85 
86 		/* first time set listen next beacon */
87 		vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_LNBCN);
88 	} else {
89 
90 		/* always listen beacon */
91 		vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_ALBCN);
92 	}
93 
94 	dev_dbg(&priv->usb->dev,  "PS:Power Saving Mode Enable...\n");
95 }
96 
97 /*
98  *
99  * Routine Description:
100  * Disable hw power saving functions
101  *
102  * Return Value:
103  *    None.
104  *
105  */
106 
vnt_disable_power_saving(struct vnt_private * priv)107 void vnt_disable_power_saving(struct vnt_private *priv)
108 {
109 
110 	/* disable power saving hw function */
111 	vnt_control_out(priv, MESSAGE_TYPE_DISABLE_PS, 0,
112 						0, 0, NULL);
113 
114 	/* clear AutoSleep */
115 	vnt_mac_reg_bits_off(priv, MAC_REG_PSCFG, PSCFG_AUTOSLEEP);
116 
117 	/* set always listen beacon */
118 	vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_ALBCN);
119 }
120 
121 /*
122  *
123  * Routine Description:
124  * Check if Next TBTT must wake up
125  *
126  * Return Value:
127  *    None.
128  *
129  */
130 
vnt_next_tbtt_wakeup(struct vnt_private * priv)131 int vnt_next_tbtt_wakeup(struct vnt_private *priv)
132 {
133 	struct ieee80211_hw *hw = priv->hw;
134 	struct ieee80211_conf *conf = &hw->conf;
135 	int wake_up = false;
136 
137 	if (conf->listen_interval == 1) {
138 		/* Turn on wake up to listen next beacon */
139 		vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_LNBCN);
140 		wake_up = true;
141 	}
142 
143 	return wake_up;
144 }
145