rfkill.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * RFKILL support for ath5k
  3. *
  4. * Copyright (c) 2009 Tobias Doerffel <tobias.doerffel@gmail.com>
  5. *
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer,
  13. * without modification.
  14. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  15. * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
  16. * redistribution must be conditioned upon including a substantially
  17. * similar Disclaimer requirement for further binary redistribution.
  18. * 3. Neither the names of the above-listed copyright holders nor the names
  19. * of any contributors may be used to endorse or promote products derived
  20. * from this software without specific prior written permission.
  21. *
  22. * NO WARRANTY
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  24. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  25. * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
  26. * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
  27. * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
  28. * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  30. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  31. * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  32. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  33. * THE POSSIBILITY OF SUCH DAMAGES.
  34. */
  35. #include "ath5k.h"
  36. static inline void ath5k_rfkill_disable(struct ath5k_hw *ah)
  37. {
  38. ATH5K_DBG(ah, ATH5K_DEBUG_ANY, "rfkill disable (gpio:%d polarity:%d)\n",
  39. ah->rf_kill.gpio, ah->rf_kill.polarity);
  40. ath5k_hw_set_gpio_output(ah, ah->rf_kill.gpio);
  41. ath5k_hw_set_gpio(ah, ah->rf_kill.gpio, !ah->rf_kill.polarity);
  42. }
  43. static inline void ath5k_rfkill_enable(struct ath5k_hw *ah)
  44. {
  45. ATH5K_DBG(ah, ATH5K_DEBUG_ANY, "rfkill enable (gpio:%d polarity:%d)\n",
  46. ah->rf_kill.gpio, ah->rf_kill.polarity);
  47. ath5k_hw_set_gpio_output(ah, ah->rf_kill.gpio);
  48. ath5k_hw_set_gpio(ah, ah->rf_kill.gpio, ah->rf_kill.polarity);
  49. }
  50. static inline void ath5k_rfkill_set_intr(struct ath5k_hw *ah, bool enable)
  51. {
  52. u32 curval;
  53. ath5k_hw_set_gpio_input(ah, ah->rf_kill.gpio);
  54. curval = ath5k_hw_get_gpio(ah, ah->rf_kill.gpio);
  55. ath5k_hw_set_gpio_intr(ah, ah->rf_kill.gpio, enable ?
  56. !!curval : !curval);
  57. }
  58. static bool
  59. ath5k_is_rfkill_set(struct ath5k_hw *ah)
  60. {
  61. /* configuring GPIO for input for some reason disables rfkill */
  62. /*ath5k_hw_set_gpio_input(ah, ah->rf_kill.gpio);*/
  63. return ath5k_hw_get_gpio(ah, ah->rf_kill.gpio) ==
  64. ah->rf_kill.polarity;
  65. }
  66. static void
  67. ath5k_tasklet_rfkill_toggle(unsigned long data)
  68. {
  69. struct ath5k_hw *ah = (void *)data;
  70. bool blocked;
  71. blocked = ath5k_is_rfkill_set(ah);
  72. wiphy_rfkill_set_hw_state(ah->hw->wiphy, blocked);
  73. }
  74. void
  75. ath5k_rfkill_hw_start(struct ath5k_hw *ah)
  76. {
  77. /* read rfkill GPIO configuration from EEPROM header */
  78. ah->rf_kill.gpio = ah->ah_capabilities.cap_eeprom.ee_rfkill_pin;
  79. ah->rf_kill.polarity = ah->ah_capabilities.cap_eeprom.ee_rfkill_pol;
  80. tasklet_init(&ah->rf_kill.toggleq, ath5k_tasklet_rfkill_toggle,
  81. (unsigned long)ah);
  82. ath5k_rfkill_disable(ah);
  83. /* enable interrupt for rfkill switch */
  84. if (AR5K_EEPROM_HDR_RFKILL(ah->ah_capabilities.cap_eeprom.ee_header))
  85. ath5k_rfkill_set_intr(ah, true);
  86. }
  87. void
  88. ath5k_rfkill_hw_stop(struct ath5k_hw *ah)
  89. {
  90. /* disable interrupt for rfkill switch */
  91. if (AR5K_EEPROM_HDR_RFKILL(ah->ah_capabilities.cap_eeprom.ee_header))
  92. ath5k_rfkill_set_intr(ah, false);
  93. tasklet_kill(&ah->rf_kill.toggleq);
  94. /* enable RFKILL when stopping HW so Wifi LED is turned off */
  95. ath5k_rfkill_enable(ah);
  96. }