power.c 2.7 KB

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