power.c 3.2 KB

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