hwrng: core - Don't use a stack buffer in add_early_randomness()
[linux/fpc-iii.git] / drivers / staging / vt6655 / power.c
blob7d6e7464ae51a1c34de5ec686451996817ead67d
1 /*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
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.
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.
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.
20 * File: power.c
22 * Purpose: Handles 802.11 power management functions
24 * Author: Lyndon Chen
26 * Date: July 17, 2002
28 * Functions:
29 * PSvEnablePowerSaving - Enable Power Saving Mode
30 * PSvDiasblePowerSaving - Disable Power Saving Mode
31 * PSbConsiderPowerDown - Decide if we can Power Down
32 * PSvSendPSPOLL - Send PS-POLL packet
33 * PSbSendNullPacket - Send Null packet
34 * PSbIsNextTBTTWakeUp - Decide if we need to wake up at next Beacon
36 * Revision History:
40 #include "mac.h"
41 #include "device.h"
42 #include "power.h"
43 #include "card.h"
45 /*--------------------- Static Definitions -------------------------*/
47 /*--------------------- Static Classes ----------------------------*/
49 /*--------------------- Static Functions --------------------------*/
51 /*--------------------- Export Variables --------------------------*/
53 /*--------------------- Export Functions --------------------------*/
57 * Routine Description:
58 * Enable hw power saving functions
60 * Return Value:
61 * None.
65 void
66 PSvEnablePowerSaving(
67 struct vnt_private *priv,
68 unsigned short wListenInterval
71 u16 wAID = priv->current_aid | BIT(14) | BIT(15);
73 /* set period of power up before TBTT */
74 VNSvOutPortW(priv->PortOffset + MAC_REG_PWBT, C_PWBT);
75 if (priv->op_mode != NL80211_IFTYPE_ADHOC) {
76 /* set AID */
77 VNSvOutPortW(priv->PortOffset + MAC_REG_AIDATIM, wAID);
78 } else {
79 /* set ATIM Window */
80 #if 0 /* TODO atim window */
81 MACvWriteATIMW(priv->PortOffset, pMgmt->wCurrATIMWindow);
82 #endif
84 /* Set AutoSleep */
85 MACvRegBitsOn(priv->PortOffset, MAC_REG_PSCFG, PSCFG_AUTOSLEEP);
86 /* Set HWUTSF */
87 MACvRegBitsOn(priv->PortOffset, MAC_REG_TFTCTL, TFTCTL_HWUTSF);
89 if (wListenInterval >= 2) {
90 /* clear always listen beacon */
91 MACvRegBitsOff(priv->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN);
92 /* first time set listen next beacon */
93 MACvRegBitsOn(priv->PortOffset, MAC_REG_PSCTL, PSCTL_LNBCN);
94 } else {
95 /* always listen beacon */
96 MACvRegBitsOn(priv->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN);
99 /* enable power saving hw function */
100 MACvRegBitsOn(priv->PortOffset, MAC_REG_PSCTL, PSCTL_PSEN);
101 priv->bEnablePSMode = true;
103 priv->bPWBitOn = true;
104 pr_debug("PS:Power Saving Mode Enable...\n");
109 * Routine Description:
110 * Disable hw power saving functions
112 * Return Value:
113 * None.
117 void
118 PSvDisablePowerSaving(
119 struct vnt_private *priv
122 /* disable power saving hw function */
123 MACbPSWakeup(priv);
124 /* clear AutoSleep */
125 MACvRegBitsOff(priv->PortOffset, MAC_REG_PSCFG, PSCFG_AUTOSLEEP);
126 /* clear HWUTSF */
127 MACvRegBitsOff(priv->PortOffset, MAC_REG_TFTCTL, TFTCTL_HWUTSF);
128 /* set always listen beacon */
129 MACvRegBitsOn(priv->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN);
131 priv->bEnablePSMode = false;
133 priv->bPWBitOn = false;
139 * Routine Description:
140 * Check if Next TBTT must wake up
142 * Return Value:
143 * None.
147 bool
148 PSbIsNextTBTTWakeUp(
149 struct vnt_private *priv
152 struct ieee80211_hw *hw = priv->hw;
153 struct ieee80211_conf *conf = &hw->conf;
154 bool wake_up = false;
156 if (conf->listen_interval > 1) {
157 if (!priv->wake_up_count)
158 priv->wake_up_count = conf->listen_interval;
160 --priv->wake_up_count;
162 if (priv->wake_up_count == 1) {
163 /* Turn on wake up to listen next beacon */
164 MACvRegBitsOn(priv->PortOffset,
165 MAC_REG_PSCTL, PSCTL_LNBCN);
166 wake_up = true;
170 return wake_up;