You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ath5k_rfkill.c 3.7KB

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