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 55void 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 /* Warren:06-18-2004,the sequence must follow 67 * PSEN->AUTOSLEEP->GO2DOZE 68 */ 69 /* enable power saving hw function */ 70 vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_PSEN); 71 72 /* Set AutoSleep */ 73 vnt_mac_reg_bits_on(priv, MAC_REG_PSCFG, PSCFG_AUTOSLEEP); 74 75 /* Warren:MUST turn on this once before turn on AUTOSLEEP ,or the 76 * AUTOSLEEP doesn't work 77 */ 78 vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_GO2DOZE); 79 80 if (listen_interval >= 2) { 81 82 /* clear always listen beacon */ 83 vnt_mac_reg_bits_off(priv, MAC_REG_PSCTL, PSCTL_ALBCN); 84 85 /* first time set listen next beacon */ 86 vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_LNBCN); 87 } else 88 89 /* always listen beacon */ 90 vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_ALBCN); 91 92 dev_dbg(&priv->usb->dev, "PS:Power Saving Mode Enable...\n"); 93} 94 95/* 96 * 97 * Routine Description: 98 * Disable hw power saving functions 99 * 100 * Return Value: 101 * None. 102 * 103 */ 104 105void vnt_disable_power_saving(struct vnt_private *priv) 106{ 107 108 /* disable power saving hw function */ 109 vnt_control_out(priv, MESSAGE_TYPE_DISABLE_PS, 0, 110 0, 0, NULL); 111 112 /* clear AutoSleep */ 113 vnt_mac_reg_bits_off(priv, MAC_REG_PSCFG, PSCFG_AUTOSLEEP); 114 115 /* set always listen beacon */ 116 vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_ALBCN); 117} 118 119/* 120 * 121 * Routine Description: 122 * Check if Next TBTT must wake up 123 * 124 * Return Value: 125 * None. 126 * 127 */ 128 129int vnt_next_tbtt_wakeup(struct vnt_private *priv) 130{ 131 struct ieee80211_hw *hw = priv->hw; 132 struct ieee80211_conf *conf = &hw->conf; 133 int wake_up = false; 134 135 if (conf->listen_interval > 1) { 136 /* Turn on wake up to listen next beacon */ 137 vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_LNBCN); 138 wake_up = true; 139 } 140 141 return wake_up; 142} 143