1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
6 * Purpose: Handles 802.11 power management functions
13 * PSvEnablePowerSaving - Enable Power Saving Mode
14 * PSvDiasblePowerSaving - Disable Power Saving Mode
15 * PSbConsiderPowerDown - Decide if we can Power Down
16 * PSvSendPSPOLL - Send PS-POLL packet
17 * PSbSendNullPacket - Send Null packet
18 * PSbIsNextTBTTWakeUp - Decide if we need to wake up at next Beacon
29 /*--------------------- Static Definitions -------------------------*/
31 /*--------------------- Static Classes ----------------------------*/
33 /*--------------------- Static Functions --------------------------*/
35 /*--------------------- Export Variables --------------------------*/
37 /*--------------------- Export Functions --------------------------*/
41 * Routine Description:
42 * Enable hw power saving functions
49 void PSvEnablePowerSaving(struct vnt_private *priv,
50 unsigned short wListenInterval)
52 u16 wAID = priv->current_aid | BIT(14) | BIT(15);
54 /* set period of power up before TBTT */
55 iowrite16(C_PWBT, priv->port_offset + MAC_REG_PWBT);
56 if (priv->op_mode != NL80211_IFTYPE_ADHOC) {
58 iowrite16(wAID, priv->port_offset + MAC_REG_AIDATIM);
62 vt6655_mac_reg_bits_on(priv->port_offset, MAC_REG_PSCFG, PSCFG_AUTOSLEEP);
65 vt6655_mac_reg_bits_on(priv->port_offset, MAC_REG_TFTCTL, TFTCTL_HWUTSF);
67 if (wListenInterval >= 2) {
68 /* clear always listen beacon */
69 vt6655_mac_reg_bits_off(priv->port_offset, MAC_REG_PSCTL, PSCTL_ALBCN);
70 /* first time set listen next beacon */
71 vt6655_mac_reg_bits_on(priv->port_offset, MAC_REG_PSCTL, PSCTL_LNBCN);
73 /* always listen beacon */
74 vt6655_mac_reg_bits_on(priv->port_offset, MAC_REG_PSCTL, PSCTL_ALBCN);
77 /* enable power saving hw function */
78 vt6655_mac_reg_bits_on(priv->port_offset, MAC_REG_PSCTL, PSCTL_PSEN);
79 priv->bEnablePSMode = true;
81 priv->bPWBitOn = true;
82 pr_debug("PS:Power Saving Mode Enable...\n");
87 * Routine Description:
88 * Disable hw power saving functions
95 void PSvDisablePowerSaving(struct vnt_private *priv)
97 /* disable power saving hw function */
100 /* clear AutoSleep */
101 vt6655_mac_reg_bits_off(priv->port_offset, MAC_REG_PSCFG, PSCFG_AUTOSLEEP);
104 vt6655_mac_reg_bits_off(priv->port_offset, MAC_REG_TFTCTL, TFTCTL_HWUTSF);
106 /* set always listen beacon */
107 vt6655_mac_reg_bits_on(priv->port_offset, MAC_REG_PSCTL, PSCTL_ALBCN);
109 priv->bEnablePSMode = false;
111 priv->bPWBitOn = false;
116 * Routine Description:
117 * Check if Next TBTT must wake up
124 bool PSbIsNextTBTTWakeUp(struct vnt_private *priv)
126 struct ieee80211_hw *hw = priv->hw;
127 struct ieee80211_conf *conf = &hw->conf;
128 bool wake_up = false;
130 if (conf->listen_interval > 1) {
131 if (!priv->wake_up_count)
132 priv->wake_up_count = conf->listen_interval;
134 --priv->wake_up_count;
136 if (priv->wake_up_count == 1) {
137 /* Turn on wake up to listen next beacon */
138 vt6655_mac_reg_bits_on(priv->port_offset, MAC_REG_PSCTL, PSCTL_LNBCN);