Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0+
0002 /*
0003  * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
0004  * All rights reserved.
0005  *
0006  * Purpose: Handles 802.11 power management functions
0007  *
0008  * Author: Lyndon Chen
0009  *
0010  * Date: July 17, 2002
0011  *
0012  * Functions:
0013  *      vnt_enable_power_saving - Enable Power Saving Mode
0014  *      PSvDiasblePowerSaving - Disable Power Saving Mode
0015  *      vnt_next_tbtt_wakeup - Decide if we need to wake up at next Beacon
0016  *
0017  * Revision History:
0018  *
0019  */
0020 
0021 #include "mac.h"
0022 #include "device.h"
0023 #include "power.h"
0024 #include "wcmd.h"
0025 #include "rxtx.h"
0026 #include "card.h"
0027 #include "usbpipe.h"
0028 
0029 /*
0030  *
0031  * Routine Description:
0032  * Enable hw power saving functions
0033  *
0034  * Return Value:
0035  *    None.
0036  *
0037  */
0038 
0039 void vnt_enable_power_saving(struct vnt_private *priv, u16 listen_interval)
0040 {
0041     u16 aid = priv->current_aid | BIT(14) | BIT(15);
0042 
0043     /* set period of power up before TBTT */
0044     vnt_mac_write_word(priv, MAC_REG_PWBT, C_PWBT);
0045 
0046     if (priv->op_mode != NL80211_IFTYPE_ADHOC)
0047         /* set AID */
0048         vnt_mac_write_word(priv, MAC_REG_AIDATIM, aid);
0049 
0050     /* Warren:06-18-2004,the sequence must follow
0051      * PSEN->AUTOSLEEP->GO2DOZE
0052      */
0053     /* enable power saving hw function */
0054     vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_PSEN);
0055 
0056     /* Set AutoSleep */
0057     vnt_mac_reg_bits_on(priv, MAC_REG_PSCFG, PSCFG_AUTOSLEEP);
0058 
0059     /* Warren:MUST turn on this once before turn on AUTOSLEEP ,or the
0060      * AUTOSLEEP doesn't work
0061      */
0062     vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_GO2DOZE);
0063 
0064     /* always listen beacon */
0065     vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_ALBCN);
0066 
0067     dev_dbg(&priv->usb->dev,  "PS:Power Saving Mode Enable...\n");
0068 }
0069 
0070 int vnt_disable_power_saving(struct vnt_private *priv)
0071 {
0072     int ret;
0073 
0074     /* disable power saving hw function */
0075     ret = vnt_control_out(priv, MESSAGE_TYPE_DISABLE_PS, 0,
0076                   0, 0, NULL);
0077     if (ret)
0078         return ret;
0079 
0080     /* clear AutoSleep */
0081     vnt_mac_reg_bits_off(priv, MAC_REG_PSCFG, PSCFG_AUTOSLEEP);
0082 
0083     /* set always listen beacon */
0084     vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_ALBCN);
0085 
0086     return 0;
0087 }
0088 
0089 /*
0090  *
0091  * Routine Description:
0092  * Check if Next TBTT must wake up
0093  *
0094  * Return Value:
0095  *    None.
0096  *
0097  */
0098 
0099 int vnt_next_tbtt_wakeup(struct vnt_private *priv)
0100 {
0101     struct ieee80211_hw *hw = priv->hw;
0102     struct ieee80211_conf *conf = &hw->conf;
0103     int wake_up = false;
0104 
0105     if (conf->listen_interval > 1) {
0106         /* Turn on wake up to listen next beacon */
0107         vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_LNBCN);
0108         wake_up = true;
0109     }
0110 
0111     return wake_up;
0112 }