rfkill.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 "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. if (dev->phy.rev >= 3) {
  23. if (!(b43_read32(dev, B43_MMIO_RADIO_HWENABLED_HI)
  24. & B43_MMIO_RADIO_HWENABLED_HI_MASK))
  25. return 1;
  26. } else {
  27. if (b43_read16(dev, B43_MMIO_RADIO_HWENABLED_LO)
  28. & B43_MMIO_RADIO_HWENABLED_LO_MASK)
  29. return 1;
  30. }
  31. return 0;
  32. }
  33. /* The poll callback for the hardware button. */
  34. void b43_rfkill_poll(struct ieee80211_hw *hw)
  35. {
  36. struct b43_wl *wl = hw_to_b43_wl(hw);
  37. struct b43_wldev *dev = wl->current_dev;
  38. struct ssb_bus *bus = dev->dev->bus;
  39. bool enabled;
  40. bool brought_up = false;
  41. mutex_lock(&wl->mutex);
  42. if (unlikely(b43_status(dev) < B43_STAT_INITIALIZED)) {
  43. if (ssb_bus_powerup(bus, 0)) {
  44. mutex_unlock(&wl->mutex);
  45. return;
  46. }
  47. ssb_device_enable(dev->dev, 0);
  48. brought_up = true;
  49. }
  50. enabled = b43_is_hw_radio_enabled(dev);
  51. if (unlikely(enabled != dev->radio_hw_enable)) {
  52. dev->radio_hw_enable = enabled;
  53. b43info(wl, "Radio hardware status changed to %s\n",
  54. enabled ? "ENABLED" : "DISABLED");
  55. wiphy_rfkill_set_hw_state(hw->wiphy, !enabled);
  56. if (enabled != dev->phy.radio_on)
  57. b43_software_rfkill(dev, !enabled);
  58. }
  59. if (brought_up) {
  60. ssb_device_disable(dev->dev, 0);
  61. ssb_bus_may_powerdown(bus);
  62. }
  63. mutex_unlock(&wl->mutex);
  64. }