2017-11-07 20:07:52 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2009-06-13 11:38:31 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* File: power.c
|
|
|
|
*
|
2012-08-26 15:16:43 +00:00
|
|
|
* Purpose: Handles 802.11 power management functions
|
2009-06-13 11:38:31 +00:00
|
|
|
*
|
|
|
|
* Author: Lyndon Chen
|
|
|
|
*
|
|
|
|
* Date: July 17, 2002
|
|
|
|
*
|
|
|
|
* Functions:
|
2014-06-04 17:25:24 +00:00
|
|
|
* vnt_enable_power_saving - Enable Power Saving Mode
|
2009-06-13 11:38:31 +00:00
|
|
|
* PSvDiasblePowerSaving - Disable Power Saving Mode
|
2014-06-04 17:25:26 +00:00
|
|
|
* vnt_next_tbtt_wakeup - Decide if we need to wake up at next Beacon
|
2009-06-13 11:38:31 +00:00
|
|
|
*
|
|
|
|
* Revision History:
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "mac.h"
|
|
|
|
#include "device.h"
|
|
|
|
#include "power.h"
|
|
|
|
#include "wcmd.h"
|
|
|
|
#include "rxtx.h"
|
|
|
|
#include "card.h"
|
2014-05-26 12:59:07 +00:00
|
|
|
#include "usbpipe.h"
|
2009-06-13 11:38:31 +00:00
|
|
|
|
2011-03-02 14:34:40 +00:00
|
|
|
/*
|
2009-06-13 11:38:31 +00:00
|
|
|
*
|
|
|
|
* Routine Description:
|
|
|
|
* Enable hw power saving functions
|
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None.
|
|
|
|
*
|
2011-03-02 14:34:40 +00:00
|
|
|
*/
|
2009-06-13 11:38:31 +00:00
|
|
|
|
2014-06-04 17:25:24 +00:00
|
|
|
void vnt_enable_power_saving(struct vnt_private *priv, u16 listen_interval)
|
2009-06-13 11:38:31 +00:00
|
|
|
{
|
2014-06-25 20:14:29 +00:00
|
|
|
u16 aid = priv->current_aid | BIT(14) | BIT(15);
|
2009-06-13 11:38:31 +00:00
|
|
|
|
2011-03-02 14:34:39 +00:00
|
|
|
/* set period of power up before TBTT */
|
2014-06-04 17:25:21 +00:00
|
|
|
vnt_mac_write_word(priv, MAC_REG_PWBT, C_PWBT);
|
2009-06-13 11:38:31 +00:00
|
|
|
|
2015-10-23 18:14:48 +00:00
|
|
|
if (priv->op_mode != NL80211_IFTYPE_ADHOC)
|
2011-03-02 14:34:39 +00:00
|
|
|
/* set AID */
|
2014-06-04 17:25:21 +00:00
|
|
|
vnt_mac_write_word(priv, MAC_REG_AIDATIM, aid);
|
2009-06-13 11:38:31 +00:00
|
|
|
|
2014-03-16 02:52:09 +00:00
|
|
|
/* Warren:06-18-2004,the sequence must follow
|
|
|
|
* PSEN->AUTOSLEEP->GO2DOZE
|
|
|
|
*/
|
2011-03-02 14:34:40 +00:00
|
|
|
/* enable power saving hw function */
|
2014-06-04 17:25:21 +00:00
|
|
|
vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_PSEN);
|
2009-06-13 11:38:31 +00:00
|
|
|
|
2011-03-02 14:34:40 +00:00
|
|
|
/* Set AutoSleep */
|
2014-06-04 17:25:21 +00:00
|
|
|
vnt_mac_reg_bits_on(priv, MAC_REG_PSCFG, PSCFG_AUTOSLEEP);
|
2009-06-13 11:38:31 +00:00
|
|
|
|
2014-03-16 02:52:09 +00:00
|
|
|
/* Warren:MUST turn on this once before turn on AUTOSLEEP ,or the
|
|
|
|
* AUTOSLEEP doesn't work
|
|
|
|
*/
|
2014-06-04 17:25:21 +00:00
|
|
|
vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_GO2DOZE);
|
2009-06-13 11:38:31 +00:00
|
|
|
|
2014-06-04 17:25:21 +00:00
|
|
|
if (listen_interval >= 2) {
|
2011-03-02 14:34:40 +00:00
|
|
|
/* clear always listen beacon */
|
2014-06-04 17:25:21 +00:00
|
|
|
vnt_mac_reg_bits_off(priv, MAC_REG_PSCTL, PSCTL_ALBCN);
|
2009-06-13 11:38:31 +00:00
|
|
|
|
2011-03-02 14:34:40 +00:00
|
|
|
/* first time set listen next beacon */
|
2014-06-04 17:25:21 +00:00
|
|
|
vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_LNBCN);
|
2017-06-30 21:38:52 +00:00
|
|
|
} else {
|
2011-03-02 14:34:40 +00:00
|
|
|
/* always listen beacon */
|
2014-06-04 17:25:21 +00:00
|
|
|
vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_ALBCN);
|
2017-06-30 21:38:52 +00:00
|
|
|
}
|
2011-03-02 14:34:39 +00:00
|
|
|
|
2014-07-16 21:22:04 +00:00
|
|
|
dev_dbg(&priv->usb->dev, "PS:Power Saving Mode Enable...\n");
|
2009-06-13 11:38:31 +00:00
|
|
|
}
|
|
|
|
|
2011-03-02 14:34:40 +00:00
|
|
|
/*
|
2009-06-13 11:38:31 +00:00
|
|
|
*
|
|
|
|
* Routine Description:
|
|
|
|
* Disable hw power saving functions
|
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None.
|
|
|
|
*
|
2011-03-02 14:34:40 +00:00
|
|
|
*/
|
2009-06-13 11:38:31 +00:00
|
|
|
|
2014-06-04 17:25:25 +00:00
|
|
|
void vnt_disable_power_saving(struct vnt_private *priv)
|
2009-06-13 11:38:31 +00:00
|
|
|
{
|
2011-03-02 14:34:40 +00:00
|
|
|
/* disable power saving hw function */
|
2014-06-04 17:25:22 +00:00
|
|
|
vnt_control_out(priv, MESSAGE_TYPE_DISABLE_PS, 0,
|
2015-12-18 08:06:24 +00:00
|
|
|
0, 0, NULL);
|
2009-06-13 11:38:31 +00:00
|
|
|
|
2011-03-02 14:34:40 +00:00
|
|
|
/* clear AutoSleep */
|
2014-06-04 17:25:22 +00:00
|
|
|
vnt_mac_reg_bits_off(priv, MAC_REG_PSCFG, PSCFG_AUTOSLEEP);
|
2009-06-13 11:38:31 +00:00
|
|
|
|
2011-03-02 14:34:40 +00:00
|
|
|
/* set always listen beacon */
|
2014-06-04 17:25:22 +00:00
|
|
|
vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_ALBCN);
|
2009-06-13 11:38:31 +00:00
|
|
|
}
|
|
|
|
|
2011-03-02 14:34:40 +00:00
|
|
|
/*
|
2009-06-13 11:38:31 +00:00
|
|
|
*
|
|
|
|
* Routine Description:
|
|
|
|
* Check if Next TBTT must wake up
|
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None.
|
|
|
|
*
|
2011-03-02 14:34:40 +00:00
|
|
|
*/
|
2009-06-13 11:38:31 +00:00
|
|
|
|
2014-06-04 17:25:26 +00:00
|
|
|
int vnt_next_tbtt_wakeup(struct vnt_private *priv)
|
2009-06-13 11:38:31 +00:00
|
|
|
{
|
2014-06-25 20:14:31 +00:00
|
|
|
struct ieee80211_hw *hw = priv->hw;
|
|
|
|
struct ieee80211_conf *conf = &hw->conf;
|
2014-06-04 17:25:23 +00:00
|
|
|
int wake_up = false;
|
2011-03-02 14:34:39 +00:00
|
|
|
|
2015-09-27 08:17:41 +00:00
|
|
|
if (conf->listen_interval > 1) {
|
2014-06-25 20:14:31 +00:00
|
|
|
/* Turn on wake up to listen next beacon */
|
|
|
|
vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_LNBCN);
|
|
|
|
wake_up = true;
|
2011-03-02 14:34:39 +00:00
|
|
|
}
|
2014-06-25 20:14:31 +00:00
|
|
|
|
2014-06-04 17:25:23 +00:00
|
|
|
return wake_up;
|
2009-06-13 11:38:31 +00:00
|
|
|
}
|