rfkill.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 "b43.h"
  19. /* Returns TRUE, if the radio is enabled in hardware. */
  20. bool b43_is_hw_radio_enabled(struct b43_wldev *dev)
  21. {
  22. return !(b43_read32(dev, B43_MMIO_RADIO_HWENABLED_HI)
  23. & B43_MMIO_RADIO_HWENABLED_HI_MASK);
  24. }
  25. /* The poll callback for the hardware button. */
  26. void b43_rfkill_poll(struct ieee80211_hw *hw)
  27. {
  28. struct b43_wl *wl = hw_to_b43_wl(hw);
  29. struct b43_wldev *dev = wl->current_dev;
  30. bool enabled;
  31. bool brought_up = false;
  32. mutex_lock(&wl->mutex);
  33. if (unlikely(b43_status(dev) < B43_STAT_INITIALIZED)) {
  34. if (b43_bus_powerup(dev, 0)) {
  35. mutex_unlock(&wl->mutex);
  36. return;
  37. }
  38. b43_device_enable(dev, 0);
  39. brought_up = true;
  40. }
  41. enabled = b43_is_hw_radio_enabled(dev);
  42. if (unlikely(enabled != dev->radio_hw_enable)) {
  43. dev->radio_hw_enable = enabled;
  44. b43info(wl, "Radio hardware status changed to %s\n",
  45. enabled ? "ENABLED" : "DISABLED");
  46. wiphy_rfkill_set_hw_state(hw->wiphy, !enabled);
  47. if (enabled != dev->phy.radio_on)
  48. b43_software_rfkill(dev, !enabled);
  49. }
  50. if (brought_up) {
  51. b43_device_disable(dev, 0);
  52. b43_bus_may_powerdown(dev);
  53. }
  54. mutex_unlock(&wl->mutex);
  55. }