power.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
  3. * All rights reserved.
  4. *
  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.
  9. *
  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.
  14. *
  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.
  18. *
  19. *
  20. * File: power.c
  21. *
  22. * Purpose: Handles 802.11 power management functions
  23. *
  24. * Author: Lyndon Chen
  25. *
  26. * Date: July 17, 2002
  27. *
  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
  35. *
  36. * Revision History:
  37. *
  38. */
  39. #include "mac.h"
  40. #include "device.h"
  41. #include "power.h"
  42. #include "card.h"
  43. /*--------------------- Static Definitions -------------------------*/
  44. /*--------------------- Static Classes ----------------------------*/
  45. /*--------------------- Static Functions --------------------------*/
  46. /*--------------------- Export Variables --------------------------*/
  47. /*--------------------- Export Functions --------------------------*/
  48. /*+
  49. *
  50. * Routine Description:
  51. * Enable hw power saving functions
  52. *
  53. * Return Value:
  54. * None.
  55. *
  56. -*/
  57. void
  58. PSvEnablePowerSaving(
  59. void *hDeviceContext,
  60. unsigned short wListenInterval
  61. )
  62. {
  63. struct vnt_private *pDevice = hDeviceContext;
  64. u16 wAID = pDevice->current_aid | BIT(14) | BIT(15);
  65. /* set period of power up before TBTT */
  66. VNSvOutPortW(pDevice->PortOffset + MAC_REG_PWBT, C_PWBT);
  67. if (pDevice->op_mode != NL80211_IFTYPE_ADHOC) {
  68. /* set AID */
  69. VNSvOutPortW(pDevice->PortOffset + MAC_REG_AIDATIM, wAID);
  70. } else {
  71. /* set ATIM Window */
  72. #if 0 /* TODO atim window */
  73. MACvWriteATIMW(pDevice->PortOffset, pMgmt->wCurrATIMWindow);
  74. #endif
  75. }
  76. /* Set AutoSleep */
  77. MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCFG, PSCFG_AUTOSLEEP);
  78. /* Set HWUTSF */
  79. MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_HWUTSF);
  80. if (wListenInterval >= 2) {
  81. /* clear always listen beacon */
  82. MACvRegBitsOff(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN);
  83. /* first time set listen next beacon */
  84. MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_LNBCN);
  85. } else {
  86. /* always listen beacon */
  87. MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN);
  88. }
  89. /* enable power saving hw function */
  90. MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PSEN);
  91. pDevice->bEnablePSMode = true;
  92. pDevice->bPWBitOn = true;
  93. pr_debug("PS:Power Saving Mode Enable...\n");
  94. }
  95. /*+
  96. *
  97. * Routine Description:
  98. * Disable hw power saving functions
  99. *
  100. * Return Value:
  101. * None.
  102. *
  103. -*/
  104. void
  105. PSvDisablePowerSaving(
  106. void *hDeviceContext
  107. )
  108. {
  109. struct vnt_private *pDevice = hDeviceContext;
  110. /* disable power saving hw function */
  111. MACbPSWakeup(pDevice->PortOffset);
  112. /* clear AutoSleep */
  113. MACvRegBitsOff(pDevice->PortOffset, MAC_REG_PSCFG, PSCFG_AUTOSLEEP);
  114. /* clear HWUTSF */
  115. MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_HWUTSF);
  116. /* set always listen beacon */
  117. MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN);
  118. pDevice->bEnablePSMode = false;
  119. pDevice->bPWBitOn = false;
  120. }
  121. /*+
  122. *
  123. * Routine Description:
  124. * Check if Next TBTT must wake up
  125. *
  126. * Return Value:
  127. * None.
  128. *
  129. -*/
  130. bool
  131. PSbIsNextTBTTWakeUp(
  132. void *hDeviceContext
  133. )
  134. {
  135. struct vnt_private *pDevice = hDeviceContext;
  136. struct ieee80211_hw *hw = pDevice->hw;
  137. struct ieee80211_conf *conf = &hw->conf;
  138. bool bWakeUp = false;
  139. if (conf->listen_interval > 1) {
  140. if (!pDevice->wake_up_count)
  141. pDevice->wake_up_count = conf->listen_interval;
  142. --pDevice->wake_up_count;
  143. if (pDevice->wake_up_count == 1) {
  144. /* Turn on wake up to listen next beacon */
  145. MACvRegBitsOn(pDevice->PortOffset,
  146. MAC_REG_PSCTL, PSCTL_LNBCN);
  147. bWakeUp = true;
  148. }
  149. }
  150. return bWakeUp;
  151. }