rfkill.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. Broadcom B43 wireless driver
  4. RFKILL support
  5. Copyright (c) 2007 Michael Buesch <m@bues.ch>
  6. */
  7. #include "radio.h"
  8. #include "b43legacy.h"
  9. /* Returns TRUE, if the radio is enabled in hardware. */
  10. bool b43legacy_is_hw_radio_enabled(struct b43legacy_wldev *dev)
  11. {
  12. if (dev->dev->id.revision >= 3) {
  13. if (!(b43legacy_read32(dev, B43legacy_MMIO_RADIO_HWENABLED_HI)
  14. & B43legacy_MMIO_RADIO_HWENABLED_HI_MASK))
  15. return true;
  16. } else {
  17. /* To prevent CPU fault on PPC, do not read a register
  18. * unless the interface is started; however, on resume
  19. * for hibernation, this routine is entered early. When
  20. * that happens, unconditionally return TRUE.
  21. */
  22. if (b43legacy_status(dev) < B43legacy_STAT_STARTED)
  23. return true;
  24. if (b43legacy_read16(dev, B43legacy_MMIO_RADIO_HWENABLED_LO)
  25. & B43legacy_MMIO_RADIO_HWENABLED_LO_MASK)
  26. return true;
  27. }
  28. return false;
  29. }
  30. /* The poll callback for the hardware button. */
  31. void b43legacy_rfkill_poll(struct ieee80211_hw *hw)
  32. {
  33. struct b43legacy_wl *wl = hw_to_b43legacy_wl(hw);
  34. struct b43legacy_wldev *dev = wl->current_dev;
  35. struct ssb_bus *bus = dev->dev->bus;
  36. bool enabled;
  37. bool brought_up = false;
  38. mutex_lock(&wl->mutex);
  39. if (unlikely(b43legacy_status(dev) < B43legacy_STAT_INITIALIZED)) {
  40. if (ssb_bus_powerup(bus, 0)) {
  41. mutex_unlock(&wl->mutex);
  42. return;
  43. }
  44. ssb_device_enable(dev->dev, 0);
  45. brought_up = true;
  46. }
  47. enabled = b43legacy_is_hw_radio_enabled(dev);
  48. if (unlikely(enabled != dev->radio_hw_enable)) {
  49. dev->radio_hw_enable = enabled;
  50. b43legacyinfo(wl, "Radio hardware status changed to %s\n",
  51. enabled ? "ENABLED" : "DISABLED");
  52. wiphy_rfkill_set_hw_state(hw->wiphy, !enabled);
  53. if (enabled != dev->phy.radio_on) {
  54. if (enabled)
  55. b43legacy_radio_turn_on(dev);
  56. else
  57. b43legacy_radio_turn_off(dev, 0);
  58. }
  59. }
  60. if (brought_up) {
  61. ssb_device_disable(dev->dev, 0);
  62. ssb_bus_may_powerdown(bus);
  63. }
  64. mutex_unlock(&wl->mutex);
  65. }