power.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. * vnt_enable_power_saving - Enable Power Saving Mode
  30. * PSvDiasblePowerSaving - Disable Power Saving Mode
  31. * vnt_next_tbtt_wakeup - Decide if we need to wake up at next Beacon
  32. *
  33. * Revision History:
  34. *
  35. */
  36. #include "mac.h"
  37. #include "device.h"
  38. #include "power.h"
  39. #include "wcmd.h"
  40. #include "rxtx.h"
  41. #include "card.h"
  42. #include "usbpipe.h"
  43. /*
  44. *
  45. * Routine Description:
  46. * Enable hw power saving functions
  47. *
  48. * Return Value:
  49. * None.
  50. *
  51. */
  52. void vnt_enable_power_saving(struct vnt_private *priv, u16 listen_interval)
  53. {
  54. u16 aid = priv->current_aid | BIT(14) | BIT(15);
  55. /* set period of power up before TBTT */
  56. vnt_mac_write_word(priv, MAC_REG_PWBT, C_PWBT);
  57. if (priv->op_mode != NL80211_IFTYPE_ADHOC) {
  58. /* set AID */
  59. vnt_mac_write_word(priv, MAC_REG_AIDATIM, aid);
  60. }
  61. /* Warren:06-18-2004,the sequence must follow
  62. * PSEN->AUTOSLEEP->GO2DOZE
  63. */
  64. /* enable power saving hw function */
  65. vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_PSEN);
  66. /* Set AutoSleep */
  67. vnt_mac_reg_bits_on(priv, MAC_REG_PSCFG, PSCFG_AUTOSLEEP);
  68. /* Warren:MUST turn on this once before turn on AUTOSLEEP ,or the
  69. * AUTOSLEEP doesn't work
  70. */
  71. vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_GO2DOZE);
  72. if (listen_interval >= 2) {
  73. /* clear always listen beacon */
  74. vnt_mac_reg_bits_off(priv, MAC_REG_PSCTL, PSCTL_ALBCN);
  75. /* first time set listen next beacon */
  76. vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_LNBCN);
  77. } else {
  78. /* always listen beacon */
  79. vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_ALBCN);
  80. }
  81. dev_dbg(&priv->usb->dev, "PS:Power Saving Mode Enable...\n");
  82. }
  83. /*
  84. *
  85. * Routine Description:
  86. * Disable hw power saving functions
  87. *
  88. * Return Value:
  89. * None.
  90. *
  91. */
  92. void vnt_disable_power_saving(struct vnt_private *priv)
  93. {
  94. /* disable power saving hw function */
  95. vnt_control_out(priv, MESSAGE_TYPE_DISABLE_PS, 0,
  96. 0, 0, NULL);
  97. /* clear AutoSleep */
  98. 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);
  101. }
  102. /*
  103. *
  104. * Routine Description:
  105. * Check if Next TBTT must wake up
  106. *
  107. * Return Value:
  108. * None.
  109. *
  110. */
  111. int vnt_next_tbtt_wakeup(struct vnt_private *priv)
  112. {
  113. struct ieee80211_hw *hw = priv->hw;
  114. struct ieee80211_conf *conf = &hw->conf;
  115. int wake_up = false;
  116. if (conf->listen_interval == 1) {
  117. /* Turn on wake up to listen next beacon */
  118. vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_LNBCN);
  119. wake_up = true;
  120. }
  121. return wake_up;
  122. }