rfkill.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 || dev->phy.type == B43_PHYTYPE_LP) {
  23. if (!(b43_read32(dev, B43_MMIO_RADIO_HWENABLED_HI)
  24. & B43_MMIO_RADIO_HWENABLED_HI_MASK))
  25. return 1;
  26. } else {
  27. /* To prevent CPU fault on PPC, do not read a register
  28. * unless the interface is started; however, on resume
  29. * for hibernation, this routine is entered early. When
  30. * that happens, unconditionally return TRUE.
  31. */
  32. if (b43_status(dev) < B43_STAT_STARTED)
  33. return 1;
  34. if (b43_read16(dev, B43_MMIO_RADIO_HWENABLED_LO)
  35. & B43_MMIO_RADIO_HWENABLED_LO_MASK)
  36. return 1;
  37. }
  38. return 0;
  39. }
  40. /* The poll callback for the hardware button. */
  41. void b43_rfkill_poll(struct ieee80211_hw *hw)
  42. {
  43. struct b43_wl *wl = hw_to_b43_wl(hw);
  44. struct b43_wldev *dev = wl->current_dev;
  45. struct ssb_bus *bus = dev->dev->bus;
  46. bool enabled;
  47. bool brought_up = false;
  48. mutex_lock(&wl->mutex);
  49. if (unlikely(b43_status(dev) < B43_STAT_INITIALIZED)) {
  50. if (ssb_bus_powerup(bus, 0)) {
  51. mutex_unlock(&wl->mutex);
  52. return;
  53. }
  54. ssb_device_enable(dev->dev, 0);
  55. brought_up = true;
  56. }
  57. enabled = b43_is_hw_radio_enabled(dev);
  58. if (unlikely(enabled != dev->radio_hw_enable)) {
  59. dev->radio_hw_enable = enabled;
  60. b43info(wl, "Radio hardware status changed to %s\n",
  61. enabled ? "ENABLED" : "DISABLED");
  62. wiphy_rfkill_set_hw_state(hw->wiphy, !enabled);
  63. if (enabled != dev->phy.radio_on)
  64. b43_software_rfkill(dev, !enabled);
  65. }
  66. if (brought_up) {
  67. ssb_device_disable(dev->dev, 0);
  68. ssb_bus_may_powerdown(bus);
  69. }
  70. mutex_unlock(&wl->mutex);
  71. }