Linux 4.19.133
[linux/fpc-iii.git] / drivers / staging / vt6656 / power.c
blob7a086c72d5a89fbf5b5e465b420ca0e3644b24dd
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
4 * All rights reserved.
6 * File: power.c
8 * Purpose: Handles 802.11 power management functions
10 * Author: Lyndon Chen
12 * Date: July 17, 2002
14 * Functions:
15 * vnt_enable_power_saving - Enable Power Saving Mode
16 * PSvDiasblePowerSaving - Disable Power Saving Mode
17 * vnt_next_tbtt_wakeup - Decide if we need to wake up at next Beacon
19 * Revision History:
23 #include "mac.h"
24 #include "device.h"
25 #include "power.h"
26 #include "wcmd.h"
27 #include "rxtx.h"
28 #include "card.h"
29 #include "usbpipe.h"
33 * Routine Description:
34 * Enable hw power saving functions
36 * Return Value:
37 * None.
41 void vnt_enable_power_saving(struct vnt_private *priv, u16 listen_interval)
43 u16 aid = priv->current_aid | BIT(14) | BIT(15);
45 /* set period of power up before TBTT */
46 vnt_mac_write_word(priv, MAC_REG_PWBT, C_PWBT);
48 if (priv->op_mode != NL80211_IFTYPE_ADHOC)
49 /* set AID */
50 vnt_mac_write_word(priv, MAC_REG_AIDATIM, aid);
52 /* Warren:06-18-2004,the sequence must follow
53 * PSEN->AUTOSLEEP->GO2DOZE
55 /* enable power saving hw function */
56 vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_PSEN);
58 /* Set AutoSleep */
59 vnt_mac_reg_bits_on(priv, MAC_REG_PSCFG, PSCFG_AUTOSLEEP);
61 /* Warren:MUST turn on this once before turn on AUTOSLEEP ,or the
62 * AUTOSLEEP doesn't work
64 vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_GO2DOZE);
66 if (listen_interval >= 2) {
67 /* clear always listen beacon */
68 vnt_mac_reg_bits_off(priv, MAC_REG_PSCTL, PSCTL_ALBCN);
70 /* first time set listen next beacon */
71 vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_LNBCN);
72 } else {
73 /* always listen beacon */
74 vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_ALBCN);
77 dev_dbg(&priv->usb->dev, "PS:Power Saving Mode Enable...\n");
82 * Routine Description:
83 * Disable hw power saving functions
85 * Return Value:
86 * None.
90 void vnt_disable_power_saving(struct vnt_private *priv)
92 /* disable power saving hw function */
93 vnt_control_out(priv, MESSAGE_TYPE_DISABLE_PS, 0,
94 0, 0, NULL);
96 /* clear AutoSleep */
97 vnt_mac_reg_bits_off(priv, MAC_REG_PSCFG, PSCFG_AUTOSLEEP);
99 /* set always listen beacon */
100 vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_ALBCN);
105 * Routine Description:
106 * Check if Next TBTT must wake up
108 * Return Value:
109 * None.
113 int vnt_next_tbtt_wakeup(struct vnt_private *priv)
115 struct ieee80211_hw *hw = priv->hw;
116 struct ieee80211_conf *conf = &hw->conf;
117 int wake_up = false;
119 if (conf->listen_interval > 1) {
120 /* Turn on wake up to listen next beacon */
121 vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_LNBCN);
122 wake_up = true;
125 return wake_up;