rfkill.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. Broadcom B43 wireless driver
  3. RFKILL support
  4. Copyright (c) 2007 Michael Buesch <mb@bu3sch.de>
  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->phy.rev >= 3) {
  24. if (!(b43legacy_read32(dev, B43legacy_MMIO_RADIO_HWENABLED_HI)
  25. & B43legacy_MMIO_RADIO_HWENABLED_HI_MASK))
  26. return 1;
  27. } else {
  28. if (b43legacy_read16(dev, B43legacy_MMIO_RADIO_HWENABLED_LO)
  29. & B43legacy_MMIO_RADIO_HWENABLED_LO_MASK)
  30. return 1;
  31. }
  32. return 0;
  33. }
  34. /* The poll callback for the hardware button. */
  35. void b43legacy_rfkill_poll(struct ieee80211_hw *hw)
  36. {
  37. struct b43legacy_wl *wl = hw_to_b43legacy_wl(hw);
  38. struct b43legacy_wldev *dev = wl->current_dev;
  39. struct ssb_bus *bus = dev->dev->bus;
  40. bool enabled;
  41. bool brought_up = false;
  42. mutex_lock(&wl->mutex);
  43. if (unlikely(b43legacy_status(dev) < B43legacy_STAT_INITIALIZED)) {
  44. if (ssb_bus_powerup(bus, 0)) {
  45. mutex_unlock(&wl->mutex);
  46. return;
  47. }
  48. ssb_device_enable(dev->dev, 0);
  49. brought_up = true;
  50. }
  51. enabled = b43legacy_is_hw_radio_enabled(dev);
  52. if (unlikely(enabled != dev->radio_hw_enable)) {
  53. dev->radio_hw_enable = enabled;
  54. b43legacyinfo(wl, "Radio hardware status changed to %s\n",
  55. enabled ? "ENABLED" : "DISABLED");
  56. wiphy_rfkill_set_hw_state(hw->wiphy, !enabled);
  57. if (enabled != dev->phy.radio_on) {
  58. if (enabled)
  59. b43legacy_radio_turn_on(dev);
  60. else
  61. b43legacy_radio_turn_off(dev, 0);
  62. }
  63. }
  64. if (brought_up) {
  65. ssb_device_disable(dev->dev, 0);
  66. ssb_bus_may_powerdown(bus);
  67. }
  68. mutex_unlock(&wl->mutex);
  69. }