Commit | Line | Data |
---|---|---|
d7c43082 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
5449c685 FB |
2 | /* |
3 | * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. | |
4 | * All rights reserved. | |
5 | * | |
5449c685 FB |
6 | * File: power.c |
7 | * | |
658ce9d6 | 8 | * Purpose: Handles 802.11 power management functions |
5449c685 FB |
9 | * |
10 | * Author: Lyndon Chen | |
11 | * | |
12 | * Date: July 17, 2002 | |
13 | * | |
14 | * Functions: | |
15 | * PSvEnablePowerSaving - Enable Power Saving Mode | |
16 | * PSvDiasblePowerSaving - Disable Power Saving Mode | |
17 | * PSbConsiderPowerDown - Decide if we can Power Down | |
18 | * PSvSendPSPOLL - Send PS-POLL packet | |
19 | * PSbSendNullPacket - Send Null packet | |
20 | * PSbIsNextTBTTWakeUp - Decide if we need to wake up at next Beacon | |
21 | * | |
22 | * Revision History: | |
23 | * | |
24 | */ | |
25 | ||
5449c685 | 26 | #include "mac.h" |
5449c685 | 27 | #include "device.h" |
5449c685 | 28 | #include "power.h" |
5449c685 | 29 | #include "card.h" |
5449c685 FB |
30 | |
31 | /*--------------------- Static Definitions -------------------------*/ | |
32 | ||
5449c685 FB |
33 | /*--------------------- Static Classes ----------------------------*/ |
34 | ||
5449c685 FB |
35 | /*--------------------- Static Functions --------------------------*/ |
36 | ||
5449c685 FB |
37 | /*--------------------- Export Variables --------------------------*/ |
38 | ||
5449c685 FB |
39 | /*--------------------- Export Functions --------------------------*/ |
40 | ||
bda457d4 | 41 | /* |
5449c685 FB |
42 | * |
43 | * Routine Description: | |
44 | * Enable hw power saving functions | |
45 | * | |
46 | * Return Value: | |
47 | * None. | |
48 | * | |
bda457d4 | 49 | */ |
5449c685 | 50 | |
6b35b7b3 | 51 | void |
5449c685 | 52 | PSvEnablePowerSaving( |
c30ab930 | 53 | struct vnt_private *priv, |
474f0f89 JP |
54 | unsigned short wListenInterval |
55 | ) | |
5449c685 | 56 | { |
16d56de6 | 57 | u16 wAID = priv->current_aid | BIT(14) | BIT(15); |
474f0f89 | 58 | |
c3dd5a08 | 59 | /* set period of power up before TBTT */ |
16d56de6 MP |
60 | VNSvOutPortW(priv->PortOffset + MAC_REG_PWBT, C_PWBT); |
61 | if (priv->op_mode != NL80211_IFTYPE_ADHOC) { | |
c3dd5a08 | 62 | /* set AID */ |
16d56de6 | 63 | VNSvOutPortW(priv->PortOffset + MAC_REG_AIDATIM, wAID); |
474f0f89 | 64 | } else { |
c3dd5a08 | 65 | /* set ATIM Window */ |
e99d357c | 66 | #if 0 /* TODO atim window */ |
16d56de6 | 67 | MACvWriteATIMW(priv->PortOffset, pMgmt->wCurrATIMWindow); |
e99d357c | 68 | #endif |
474f0f89 | 69 | } |
c3dd5a08 | 70 | /* Set AutoSleep */ |
16d56de6 | 71 | MACvRegBitsOn(priv->PortOffset, MAC_REG_PSCFG, PSCFG_AUTOSLEEP); |
c3dd5a08 | 72 | /* Set HWUTSF */ |
16d56de6 | 73 | MACvRegBitsOn(priv->PortOffset, MAC_REG_TFTCTL, TFTCTL_HWUTSF); |
474f0f89 JP |
74 | |
75 | if (wListenInterval >= 2) { | |
c3dd5a08 | 76 | /* clear always listen beacon */ |
16d56de6 | 77 | MACvRegBitsOff(priv->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN); |
c3dd5a08 | 78 | /* first time set listen next beacon */ |
16d56de6 | 79 | MACvRegBitsOn(priv->PortOffset, MAC_REG_PSCTL, PSCTL_LNBCN); |
5e0cc8a2 | 80 | } else { |
c3dd5a08 | 81 | /* always listen beacon */ |
16d56de6 | 82 | MACvRegBitsOn(priv->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN); |
474f0f89 JP |
83 | } |
84 | ||
c3dd5a08 | 85 | /* enable power saving hw function */ |
16d56de6 MP |
86 | MACvRegBitsOn(priv->PortOffset, MAC_REG_PSCTL, PSCTL_PSEN); |
87 | priv->bEnablePSMode = true; | |
474f0f89 | 88 | |
16d56de6 | 89 | priv->bPWBitOn = true; |
48caf5a0 | 90 | pr_debug("PS:Power Saving Mode Enable...\n"); |
5449c685 FB |
91 | } |
92 | ||
bda457d4 | 93 | /* |
5449c685 FB |
94 | * |
95 | * Routine Description: | |
96 | * Disable hw power saving functions | |
97 | * | |
98 | * Return Value: | |
99 | * None. | |
100 | * | |
bda457d4 | 101 | */ |
5449c685 | 102 | |
6b35b7b3 | 103 | void |
5449c685 | 104 | PSvDisablePowerSaving( |
c30ab930 | 105 | struct vnt_private *priv |
474f0f89 | 106 | ) |
5449c685 | 107 | { |
c3dd5a08 | 108 | /* disable power saving hw function */ |
f9f853af | 109 | MACbPSWakeup(priv); |
c3dd5a08 | 110 | /* clear AutoSleep */ |
16d56de6 | 111 | MACvRegBitsOff(priv->PortOffset, MAC_REG_PSCFG, PSCFG_AUTOSLEEP); |
c3dd5a08 | 112 | /* clear HWUTSF */ |
16d56de6 | 113 | MACvRegBitsOff(priv->PortOffset, MAC_REG_TFTCTL, TFTCTL_HWUTSF); |
c3dd5a08 | 114 | /* set always listen beacon */ |
16d56de6 | 115 | MACvRegBitsOn(priv->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN); |
474f0f89 | 116 | |
16d56de6 | 117 | priv->bEnablePSMode = false; |
474f0f89 | 118 | |
16d56de6 | 119 | priv->bPWBitOn = false; |
5449c685 FB |
120 | } |
121 | ||
bda457d4 | 122 | /* |
5449c685 FB |
123 | * |
124 | * Routine Description: | |
125 | * Check if Next TBTT must wake up | |
126 | * | |
127 | * Return Value: | |
128 | * None. | |
129 | * | |
bda457d4 | 130 | */ |
5449c685 | 131 | |
7b6a0013 | 132 | bool |
5449c685 | 133 | PSbIsNextTBTTWakeUp( |
c30ab930 | 134 | struct vnt_private *priv |
474f0f89 | 135 | ) |
5449c685 | 136 | { |
16d56de6 | 137 | struct ieee80211_hw *hw = priv->hw; |
e24c235b | 138 | struct ieee80211_conf *conf = &hw->conf; |
a977551b | 139 | bool wake_up = false; |
5449c685 | 140 | |
3e7921a0 | 141 | if (conf->listen_interval > 1) { |
16d56de6 MP |
142 | if (!priv->wake_up_count) |
143 | priv->wake_up_count = conf->listen_interval; | |
3e7921a0 | 144 | |
16d56de6 | 145 | --priv->wake_up_count; |
3e7921a0 | 146 | |
16d56de6 | 147 | if (priv->wake_up_count == 1) { |
3e7921a0 | 148 | /* Turn on wake up to listen next beacon */ |
16d56de6 | 149 | MACvRegBitsOn(priv->PortOffset, |
3e7921a0 | 150 | MAC_REG_PSCTL, PSCTL_LNBCN); |
a977551b | 151 | wake_up = true; |
3e7921a0 | 152 | } |
474f0f89 | 153 | } |
5449c685 | 154 | |
a977551b | 155 | return wake_up; |
5449c685 | 156 | } |