Commit | Line | Data |
---|---|---|
92b96797 FB |
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 | * | |
92b96797 FB |
15 | * |
16 | * File: power.c | |
17 | * | |
a0a1f61a | 18 | * Purpose: Handles 802.11 power management functions |
92b96797 FB |
19 | * |
20 | * Author: Lyndon Chen | |
21 | * | |
22 | * Date: July 17, 2002 | |
23 | * | |
24 | * Functions: | |
c1d45af9 | 25 | * vnt_enable_power_saving - Enable Power Saving Mode |
92b96797 | 26 | * PSvDiasblePowerSaving - Disable Power Saving Mode |
bb73fd04 | 27 | * vnt_next_tbtt_wakeup - Decide if we need to wake up at next Beacon |
92b96797 FB |
28 | * |
29 | * Revision History: | |
30 | * | |
31 | */ | |
32 | ||
92b96797 | 33 | #include "mac.h" |
92b96797 | 34 | #include "device.h" |
92b96797 | 35 | #include "power.h" |
92b96797 | 36 | #include "wcmd.h" |
92b96797 | 37 | #include "rxtx.h" |
92b96797 | 38 | #include "card.h" |
62c8526d | 39 | #include "usbpipe.h" |
92b96797 | 40 | |
7404eab2 | 41 | /* |
92b96797 FB |
42 | * |
43 | * Routine Description: | |
44 | * Enable hw power saving functions | |
45 | * | |
46 | * Return Value: | |
47 | * None. | |
48 | * | |
7404eab2 | 49 | */ |
92b96797 | 50 | |
c1d45af9 | 51 | void vnt_enable_power_saving(struct vnt_private *priv, u16 listen_interval) |
92b96797 | 52 | { |
bbdf1bd4 | 53 | u16 aid = priv->current_aid | BIT(14) | BIT(15); |
92b96797 | 54 | |
f9cfbe94 | 55 | /* set period of power up before TBTT */ |
2bac6f98 | 56 | vnt_mac_write_word(priv, MAC_REG_PWBT, C_PWBT); |
92b96797 | 57 | |
7526a468 | 58 | if (priv->op_mode != NL80211_IFTYPE_ADHOC) |
f9cfbe94 | 59 | /* set AID */ |
2bac6f98 | 60 | vnt_mac_write_word(priv, MAC_REG_AIDATIM, aid); |
92b96797 | 61 | |
64052b78 AO |
62 | /* Warren:06-18-2004,the sequence must follow |
63 | * PSEN->AUTOSLEEP->GO2DOZE | |
64 | */ | |
7404eab2 | 65 | /* enable power saving hw function */ |
2bac6f98 | 66 | vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_PSEN); |
92b96797 | 67 | |
7404eab2 | 68 | /* Set AutoSleep */ |
2bac6f98 | 69 | vnt_mac_reg_bits_on(priv, MAC_REG_PSCFG, PSCFG_AUTOSLEEP); |
92b96797 | 70 | |
64052b78 AO |
71 | /* Warren:MUST turn on this once before turn on AUTOSLEEP ,or the |
72 | * AUTOSLEEP doesn't work | |
73 | */ | |
2bac6f98 | 74 | vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_GO2DOZE); |
92b96797 | 75 | |
2bac6f98 | 76 | if (listen_interval >= 2) { |
92b96797 | 77 | |
7404eab2 | 78 | /* clear always listen beacon */ |
2bac6f98 | 79 | vnt_mac_reg_bits_off(priv, MAC_REG_PSCTL, PSCTL_ALBCN); |
92b96797 | 80 | |
7404eab2 | 81 | /* first time set listen next beacon */ |
2bac6f98 | 82 | vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_LNBCN); |
7526a468 | 83 | } else |
92b96797 | 84 | |
7404eab2 | 85 | /* always listen beacon */ |
2bac6f98 | 86 | vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_ALBCN); |
f9cfbe94 | 87 | |
752b7daf | 88 | dev_dbg(&priv->usb->dev, "PS:Power Saving Mode Enable...\n"); |
92b96797 FB |
89 | } |
90 | ||
7404eab2 | 91 | /* |
92b96797 FB |
92 | * |
93 | * Routine Description: | |
94 | * Disable hw power saving functions | |
95 | * | |
96 | * Return Value: | |
97 | * None. | |
98 | * | |
7404eab2 | 99 | */ |
92b96797 | 100 | |
905dba5c | 101 | void vnt_disable_power_saving(struct vnt_private *priv) |
92b96797 | 102 | { |
92b96797 | 103 | |
7404eab2 | 104 | /* disable power saving hw function */ |
38c7b5b5 | 105 | vnt_control_out(priv, MESSAGE_TYPE_DISABLE_PS, 0, |
1eba248a | 106 | 0, 0, NULL); |
92b96797 | 107 | |
7404eab2 | 108 | /* clear AutoSleep */ |
38c7b5b5 | 109 | vnt_mac_reg_bits_off(priv, MAC_REG_PSCFG, PSCFG_AUTOSLEEP); |
92b96797 | 110 | |
7404eab2 | 111 | /* set always listen beacon */ |
38c7b5b5 | 112 | vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_ALBCN); |
92b96797 FB |
113 | } |
114 | ||
7404eab2 | 115 | /* |
92b96797 FB |
116 | * |
117 | * Routine Description: | |
118 | * Check if Next TBTT must wake up | |
119 | * | |
120 | * Return Value: | |
121 | * None. | |
122 | * | |
7404eab2 | 123 | */ |
92b96797 | 124 | |
bb73fd04 | 125 | int vnt_next_tbtt_wakeup(struct vnt_private *priv) |
92b96797 | 126 | { |
f7c7f7f2 MP |
127 | struct ieee80211_hw *hw = priv->hw; |
128 | struct ieee80211_conf *conf = &hw->conf; | |
bedf4efa | 129 | int wake_up = false; |
f9cfbe94 | 130 | |
43c93d9b | 131 | if (conf->listen_interval > 1) { |
f7c7f7f2 MP |
132 | /* Turn on wake up to listen next beacon */ |
133 | vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_LNBCN); | |
134 | wake_up = true; | |
f9cfbe94 | 135 | } |
f7c7f7f2 | 136 | |
bedf4efa | 137 | return wake_up; |
92b96797 | 138 | } |