16b4c6ce8SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0+
292b96797SForest Bond /*
392b96797SForest Bond * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
492b96797SForest Bond * All rights reserved.
592b96797SForest Bond *
60d743951SUwe Kleine-König * Purpose: Handles 802.11 power management functions
792b96797SForest Bond *
892b96797SForest Bond * Author: Lyndon Chen
992b96797SForest Bond *
1092b96797SForest Bond * Date: July 17, 2002
1192b96797SForest Bond *
1292b96797SForest Bond * Functions:
13c1d45af9SMalcolm Priestley * vnt_enable_power_saving - Enable Power Saving Mode
1492b96797SForest Bond * PSvDiasblePowerSaving - Disable Power Saving Mode
15bb73fd04SMalcolm Priestley * vnt_next_tbtt_wakeup - Decide if we need to wake up at next Beacon
1692b96797SForest Bond *
1792b96797SForest Bond * Revision History:
1892b96797SForest Bond *
1992b96797SForest Bond */
2092b96797SForest Bond
2192b96797SForest Bond #include "mac.h"
2292b96797SForest Bond #include "device.h"
2392b96797SForest Bond #include "power.h"
2492b96797SForest Bond #include "wcmd.h"
2592b96797SForest Bond #include "rxtx.h"
2692b96797SForest Bond #include "card.h"
2762c8526dSMalcolm Priestley #include "usbpipe.h"
2892b96797SForest Bond
297404eab2SPhilip Worrall /*
3092b96797SForest Bond *
3192b96797SForest Bond * Routine Description:
3292b96797SForest Bond * Enable hw power saving functions
3392b96797SForest Bond *
3492b96797SForest Bond * Return Value:
3592b96797SForest Bond * None.
3692b96797SForest Bond *
377404eab2SPhilip Worrall */
3892b96797SForest Bond
vnt_enable_power_saving(struct vnt_private * priv,u16 listen_interval)39c1d45af9SMalcolm Priestley void vnt_enable_power_saving(struct vnt_private *priv, u16 listen_interval)
4092b96797SForest Bond {
41bbdf1bd4SMalcolm Priestley u16 aid = priv->current_aid | BIT(14) | BIT(15);
4292b96797SForest Bond
434846cbc1SAlejandro Emanuel Paredes /* set period of power up before TBTT */
442bac6f98SMalcolm Priestley vnt_mac_write_word(priv, MAC_REG_PWBT, C_PWBT);
4592b96797SForest Bond
467526a468SAmitoj Kaur Chawla if (priv->op_mode != NL80211_IFTYPE_ADHOC)
474846cbc1SAlejandro Emanuel Paredes /* set AID */
482bac6f98SMalcolm Priestley vnt_mac_write_word(priv, MAC_REG_AIDATIM, aid);
4992b96797SForest Bond
5064052b78SAybuke Ozdemir /* Warren:06-18-2004,the sequence must follow
5164052b78SAybuke Ozdemir * PSEN->AUTOSLEEP->GO2DOZE
5264052b78SAybuke Ozdemir */
537404eab2SPhilip Worrall /* enable power saving hw function */
542bac6f98SMalcolm Priestley vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_PSEN);
55f9cfbe94SPhilip Worrall
567404eab2SPhilip Worrall /* Set AutoSleep */
572bac6f98SMalcolm Priestley vnt_mac_reg_bits_on(priv, MAC_REG_PSCFG, PSCFG_AUTOSLEEP);
5892b96797SForest Bond
5964052b78SAybuke Ozdemir /* Warren:MUST turn on this once before turn on AUTOSLEEP ,or the
6064052b78SAybuke Ozdemir * AUTOSLEEP doesn't work
6164052b78SAybuke Ozdemir */
622bac6f98SMalcolm Priestley vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_GO2DOZE);
6392b96797SForest Bond
647404eab2SPhilip Worrall /* always listen beacon */
652bac6f98SMalcolm Priestley vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_ALBCN);
6692b96797SForest Bond
67752b7dafSMalcolm Priestley dev_dbg(&priv->usb->dev, "PS:Power Saving Mode Enable...\n");
6892b96797SForest Bond }
6992b96797SForest Bond
vnt_disable_power_saving(struct vnt_private * priv)7081969fd8SOscar Carter int vnt_disable_power_saving(struct vnt_private *priv)
7192b96797SForest Bond {
7281969fd8SOscar Carter int ret;
7381969fd8SOscar Carter
747404eab2SPhilip Worrall /* disable power saving hw function */
7581969fd8SOscar Carter ret = vnt_control_out(priv, MESSAGE_TYPE_DISABLE_PS, 0,
76f9cfbe94SPhilip Worrall 0, 0, NULL);
7781969fd8SOscar Carter if (ret)
7881969fd8SOscar Carter return ret;
7992b96797SForest Bond
807404eab2SPhilip Worrall /* clear AutoSleep */
8138c7b5b5SMalcolm Priestley vnt_mac_reg_bits_off(priv, MAC_REG_PSCFG, PSCFG_AUTOSLEEP);
8292b96797SForest Bond
837404eab2SPhilip Worrall /* set always listen beacon */
8438c7b5b5SMalcolm Priestley vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_ALBCN);
8581969fd8SOscar Carter
8681969fd8SOscar Carter return 0;
8792b96797SForest Bond }
8892b96797SForest Bond
897404eab2SPhilip Worrall /*
9092b96797SForest Bond *
9192b96797SForest Bond * Routine Description:
9292b96797SForest Bond * Check if Next TBTT must wake up
9392b96797SForest Bond *
9492b96797SForest Bond * Return Value:
9592b96797SForest Bond * None.
9692b96797SForest Bond *
977404eab2SPhilip Worrall */
9892b96797SForest Bond
vnt_next_tbtt_wakeup(struct vnt_private * priv)99bb73fd04SMalcolm Priestley int vnt_next_tbtt_wakeup(struct vnt_private *priv)
10092b96797SForest Bond {
101f7c7f7f2SMalcolm Priestley struct ieee80211_hw *hw = priv->hw;
102f7c7f7f2SMalcolm Priestley struct ieee80211_conf *conf = &hw->conf;
103bedf4efaSMalcolm Priestley int wake_up = false;
10492b96797SForest Bond
10543c93d9bSMalcolm Priestley if (conf->listen_interval > 1) {
1067404eab2SPhilip Worrall /* Turn on wake up to listen next beacon */
107bedf4efaSMalcolm Priestley vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_LNBCN);
108bedf4efaSMalcolm Priestley wake_up = true;
10992b96797SForest Bond }
11092b96797SForest Bond
111f7c7f7f2SMalcolm Priestley return wake_up;
112f7c7f7f2SMalcolm Priestley }
113