drm/i915: Move non-phys cursors into the GTT
[linux/fpc-iii.git] / drivers / staging / vt6656 / power.c
blob766c5be6fd22e51d82324d0ccf93bc3c5d1d8011
1 /*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 * File: power.c
22 * Purpose: Handles 802.11 power managment functions
24 * Author: Lyndon Chen
26 * Date: July 17, 2002
28 * Functions:
29 * PSvEnablePowerSaving - Enable Power Saving Mode
30 * PSvDiasblePowerSaving - Disable Power Saving Mode
31 * PSbConsiderPowerDown - Decide if we can Power Down
32 * PSvSendPSPOLL - Send PS-POLL packet
33 * PSbSendNullPacket - Send Null packet
34 * PSbIsNextTBTTWakeUp - Decide if we need to wake up at next Beacon
36 * Revision History:
40 #include "ttype.h"
41 #include "mac.h"
42 #include "device.h"
43 #include "wmgr.h"
44 #include "power.h"
45 #include "wcmd.h"
46 #include "rxtx.h"
47 #include "card.h"
48 #include "control.h"
49 #include "rndis.h"
51 /*--------------------- Static Definitions -------------------------*/
53 /*--------------------- Static Classes ----------------------------*/
55 /*--------------------- Static Variables --------------------------*/
56 static int msglevel =MSG_LEVEL_INFO;
57 /*--------------------- Static Functions --------------------------*/
59 /*--------------------- Export Variables --------------------------*/
61 /*--------------------- Export Functions --------------------------*/
63 /*+
65 * Routine Description:
66 * Enable hw power saving functions
68 * Return Value:
69 * None.
71 -*/
73 void PSvEnablePowerSaving(void *hDeviceContext,
74 WORD wListenInterval)
76 PSDevice pDevice = (PSDevice)hDeviceContext;
77 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
78 WORD wAID = pMgmt->wCurrAID | BIT14 | BIT15;
80 // set period of power up before TBTT
81 MACvWriteWord(pDevice, MAC_REG_PWBT, C_PWBT);
83 if (pDevice->eOPMode != OP_MODE_ADHOC) {
84 // set AID
85 MACvWriteWord(pDevice, MAC_REG_AIDATIM, wAID);
86 } else {
87 // set ATIM Window
88 //MACvWriteATIMW(pDevice->PortOffset, pMgmt->wCurrATIMWindow);
91 //Warren:06-18-2004,the sequence must follow PSEN->AUTOSLEEP->GO2DOZE
92 // enable power saving hw function
93 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_PSEN);
94 // Set AutoSleep
95 MACvRegBitsOn(pDevice, MAC_REG_PSCFG, PSCFG_AUTOSLEEP);
97 //Warren:MUST turn on this once before turn on AUTOSLEEP ,or the AUTOSLEEP doesn't work
98 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_GO2DOZE);
101 if (wListenInterval >= 2) {
103 // clear always listen beacon
104 MACvRegBitsOff(pDevice, MAC_REG_PSCTL, PSCTL_ALBCN);
105 // first time set listen next beacon
106 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_LNBCN);
108 pMgmt->wCountToWakeUp = wListenInterval;
111 else {
113 // always listen beacon
114 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_ALBCN);
115 pMgmt->wCountToWakeUp = 0;
119 pDevice->bEnablePSMode = TRUE;
121 if (pDevice->eOPMode == OP_MODE_ADHOC) {
122 /* bMgrPrepareBeaconToSend((void *) pDevice, pMgmt); */
124 // We don't send null pkt in ad hoc mode since beacon will handle this.
125 else if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
126 PSbSendNullPacket(pDevice);
128 pDevice->bPWBitOn = TRUE;
129 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "PS:Power Saving Mode Enable... \n");
130 return;
135 * Routine Description:
136 * Disable hw power saving functions
138 * Return Value:
139 * None.
143 void PSvDisablePowerSaving(void *hDeviceContext)
145 PSDevice pDevice = (PSDevice)hDeviceContext;
146 // PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
149 // disable power saving hw function
150 CONTROLnsRequestOut(pDevice,
151 MESSAGE_TYPE_DISABLE_PS,
155 NULL
158 //clear AutoSleep
159 MACvRegBitsOff(pDevice, MAC_REG_PSCFG, PSCFG_AUTOSLEEP);
161 // set always listen beacon
162 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_ALBCN);
164 pDevice->bEnablePSMode = FALSE;
166 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
167 PSbSendNullPacket(pDevice);
169 pDevice->bPWBitOn = FALSE;
170 return;
175 * Routine Description:
176 * Consider to power down when no more packets to tx or rx.
178 * Return Value:
179 * TRUE, if power down success
180 * FALSE, if fail
183 BOOL PSbConsiderPowerDown(void *hDeviceContext,
184 BOOL bCheckRxDMA,
185 BOOL bCheckCountToWakeUp)
187 PSDevice pDevice = (PSDevice)hDeviceContext;
188 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
189 BYTE byData;
192 // check if already in Doze mode
193 ControlvReadByte(pDevice, MESSAGE_REQUEST_MACREG, MAC_REG_PSCTL, &byData);
194 if ( (byData & PSCTL_PS) != 0 )
195 return TRUE;;
197 if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) {
198 // check if in TIM wake period
199 if (pMgmt->bInTIMWake)
200 return FALSE;
203 // check scan state
204 if (pDevice->bCmdRunning)
205 return FALSE;
207 //Tx Burst
208 if ( pDevice->bPSModeTxBurst )
209 return FALSE;
211 // Froce PSEN on
212 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_PSEN);
214 if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) {
215 if (bCheckCountToWakeUp &&
216 (pMgmt->wCountToWakeUp == 0 || pMgmt->wCountToWakeUp == 1)) {
217 return FALSE;
221 pDevice->bPSRxBeacon = TRUE;
222 // no Tx, no Rx isr, now go to Doze
223 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_GO2DOZE);
225 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Go to Doze ZZZZZZZZZZZZZZZ\n");
226 return TRUE;
231 * Routine Description:
232 * Send PS-POLL packet
234 * Return Value:
235 * None.
239 void PSvSendPSPOLL(void *hDeviceContext)
241 PSDevice pDevice = (PSDevice)hDeviceContext;
242 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
243 PSTxMgmtPacket pTxPacket = NULL;
246 memset(pMgmt->pbyPSPacketPool, 0, sizeof(STxMgmtPacket) + WLAN_HDR_ADDR2_LEN);
247 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyPSPacketPool;
248 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket));
249 pTxPacket->p80211Header->sA2.wFrameCtl = cpu_to_le16(
251 WLAN_SET_FC_FTYPE(WLAN_TYPE_CTL) |
252 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PSPOLL) |
253 WLAN_SET_FC_PWRMGT(0)
255 pTxPacket->p80211Header->sA2.wDurationID = pMgmt->wCurrAID | BIT14 | BIT15;
256 memcpy(pTxPacket->p80211Header->sA2.abyAddr1, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
257 memcpy(pTxPacket->p80211Header->sA2.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
258 pTxPacket->cbMPDULen = WLAN_HDR_ADDR2_LEN;
259 pTxPacket->cbPayloadLen = 0;
260 // send the frame
261 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
262 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send PS-Poll packet failed..\n");
264 else {
265 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send PS-Poll packet success..\n");
268 return;
273 * Routine Description:
274 * Send NULL packet to AP for notification power state of STA
276 * Return Value:
277 * None.
281 BOOL PSbSendNullPacket(void *hDeviceContext)
283 PSDevice pDevice = (PSDevice)hDeviceContext;
284 PSTxMgmtPacket pTxPacket = NULL;
285 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
289 if (pDevice->bLinkPass == FALSE) {
290 return FALSE;
293 //2007-0115-03<Add>by MikeLiu
294 #ifdef TxInSleep
295 if ((pDevice->bEnablePSMode == FALSE) &&
296 (pDevice->fTxDataInSleep == FALSE)){
297 return FALSE;
299 #else
300 if (pDevice->bEnablePSMode == FALSE) {
301 return FALSE;
303 #endif
304 memset(pMgmt->pbyPSPacketPool, 0, sizeof(STxMgmtPacket) + WLAN_NULLDATA_FR_MAXLEN);
305 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyPSPacketPool;
306 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket));
308 if (pDevice->bEnablePSMode) {
310 pTxPacket->p80211Header->sA3.wFrameCtl = cpu_to_le16(
312 WLAN_SET_FC_FTYPE(WLAN_TYPE_DATA) |
313 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_NULL) |
314 WLAN_SET_FC_PWRMGT(1)
317 else {
318 pTxPacket->p80211Header->sA3.wFrameCtl = cpu_to_le16(
320 WLAN_SET_FC_FTYPE(WLAN_TYPE_DATA) |
321 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_NULL) |
322 WLAN_SET_FC_PWRMGT(0)
326 if(pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) {
327 pTxPacket->p80211Header->sA3.wFrameCtl |= cpu_to_le16((WORD)WLAN_SET_FC_TODS(1));
330 memcpy(pTxPacket->p80211Header->sA3.abyAddr1, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
331 memcpy(pTxPacket->p80211Header->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
332 memcpy(pTxPacket->p80211Header->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
333 pTxPacket->cbMPDULen = WLAN_HDR_ADDR3_LEN;
334 pTxPacket->cbPayloadLen = 0;
335 // send the frame
336 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
337 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send Null Packet failed !\n");
338 return FALSE;
340 else {
341 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send Null Packet success....\n");
345 return TRUE ;
350 * Routine Description:
351 * Check if Next TBTT must wake up
353 * Return Value:
354 * None.
358 BOOL PSbIsNextTBTTWakeUp(void *hDeviceContext)
361 PSDevice pDevice = (PSDevice)hDeviceContext;
362 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
363 BOOL bWakeUp = FALSE;
365 if (pMgmt->wListenInterval >= 2) {
366 if (pMgmt->wCountToWakeUp == 0) {
367 pMgmt->wCountToWakeUp = pMgmt->wListenInterval;
370 pMgmt->wCountToWakeUp --;
372 if (pMgmt->wCountToWakeUp == 1) {
374 // Turn on wake up to listen next beacon
375 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_LNBCN);
376 pDevice->bPSRxBeacon = FALSE;
377 bWakeUp = TRUE;
379 } else if ( !pDevice->bPSRxBeacon ) {
380 //Listen until RxBeacon
381 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_LNBCN);
386 return bWakeUp;