rfkill.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. Broadcom B43 wireless driver
  3. RFKILL support
  4. Copyright (c) 2007 Michael Buesch <m@bues.ch>
  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. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; see the file COPYING. If not, write to
  15. the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
  16. Boston, MA 02110-1301, USA.
  17. */
  18. #include "radio.h"
  19. #include "b43legacy.h"
  20. /* Returns TRUE, if the radio is enabled in hardware. */
  21. bool b43legacy_is_hw_radio_enabled(struct b43legacy_wldev *dev)
  22. {
  23. if (dev->dev->id.revision >= 3) {
  24. if (!(b43legacy_read32(dev, B43legacy_MMIO_RADIO_HWENABLED_HI)
  25. & B43legacy_MMIO_RADIO_HWENABLED_HI_MASK))
  26. return true;
  27. } else {
  28. /* To prevent CPU fault on PPC, do not read a register
  29. * unless the interface is started; however, on resume
  30. * for hibernation, this routine is entered early. When
  31. * that happens, unconditionally return TRUE.
  32. */
  33. if (b43legacy_status(dev) < B43legacy_STAT_STARTED)
  34. return true;
  35. if (b43legacy_read16(dev, B43legacy_MMIO_RADIO_HWENABLED_LO)
  36. & B43legacy_MMIO_RADIO_HWENABLED_LO_MASK)
  37. return true;
  38. }
  39. return false;
  40. }
  41. /* The poll callback for the hardware button. */
  42. void b43legacy_rfkill_poll(struct ieee80211_hw *hw)
  43. {
  44. struct b43legacy_wl *wl = hw_to_b43legacy_wl(hw);
  45. struct b43legacy_wldev *dev = wl->current_dev;
  46. struct ssb_bus *bus = dev->dev->bus;
  47. bool enabled;
  48. bool brought_up = false;
  49. mutex_lock(&wl->mutex);
  50. if (unlikely(b43legacy_status(dev) < B43legacy_STAT_INITIALIZED)) {
  51. if (ssb_bus_powerup(bus, 0)) {
  52. mutex_unlock(&wl->mutex);
  53. return;
  54. }
  55. ssb_device_enable(dev->dev, 0);
  56. brought_up = true;
  57. }
  58. enabled = b43legacy_is_hw_radio_enabled(dev);
  59. if (unlikely(enabled != dev->radio_hw_enable)) {
  60. dev->radio_hw_enable = enabled;
  61. b43legacyinfo(wl, "Radio hardware status changed to %s\n",
  62. enabled ? "ENABLED" : "DISABLED");
  63. wiphy_rfkill_set_hw_state(hw->wiphy, !enabled);
  64. if (enabled != dev->phy.radio_on) {
  65. if (enabled)
  66. b43legacy_radio_turn_on(dev);
  67. else
  68. b43legacy_radio_turn_off(dev, 0);
  69. }
  70. }
  71. if (brought_up) {
  72. ssb_device_disable(dev->dev, 0);
  73. ssb_bus_may_powerdown(bus);
  74. }
  75. mutex_unlock(&wl->mutex);
  76. }