rfkill.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. Broadcom B43 wireless driver
  4. RFKILL support
  5. Copyright (c) 2007 Michael Buesch <[email protected]>
  6. */
  7. #include "b43.h"
  8. /* Returns TRUE, if the radio is enabled in hardware. */
  9. bool b43_is_hw_radio_enabled(struct b43_wldev *dev)
  10. {
  11. return !(b43_read32(dev, B43_MMIO_RADIO_HWENABLED_HI)
  12. & B43_MMIO_RADIO_HWENABLED_HI_MASK);
  13. }
  14. /* The poll callback for the hardware button. */
  15. void b43_rfkill_poll(struct ieee80211_hw *hw)
  16. {
  17. struct b43_wl *wl = hw_to_b43_wl(hw);
  18. struct b43_wldev *dev = wl->current_dev;
  19. bool enabled;
  20. bool brought_up = false;
  21. mutex_lock(&wl->mutex);
  22. if (unlikely(b43_status(dev) < B43_STAT_INITIALIZED)) {
  23. if (b43_bus_powerup(dev, 0)) {
  24. mutex_unlock(&wl->mutex);
  25. return;
  26. }
  27. b43_device_enable(dev, 0);
  28. brought_up = true;
  29. }
  30. enabled = b43_is_hw_radio_enabled(dev);
  31. if (unlikely(enabled != dev->radio_hw_enable)) {
  32. dev->radio_hw_enable = enabled;
  33. b43info(wl, "Radio hardware status changed to %s\n",
  34. enabled ? "ENABLED" : "DISABLED");
  35. wiphy_rfkill_set_hw_state(hw->wiphy, !enabled);
  36. if (enabled != dev->phy.radio_on)
  37. b43_software_rfkill(dev, !enabled);
  38. }
  39. if (brought_up) {
  40. b43_device_disable(dev, 0);
  41. b43_bus_may_powerdown(dev);
  42. }
  43. mutex_unlock(&wl->mutex);
  44. }