| Michael Buesch | 8e9f752 | 2007-09-27 21:35:34 +0200 | [diff] [blame] | 1 | /* | 
|  | 2 |  | 
|  | 3 | Broadcom B43 wireless driver | 
|  | 4 | RFKILL support | 
|  | 5 |  | 
|  | 6 | Copyright (c) 2007 Michael Buesch <mb@bu3sch.de> | 
|  | 7 |  | 
|  | 8 | This program is free software; you can redistribute it and/or modify | 
|  | 9 | it under the terms of the GNU General Public License as published by | 
|  | 10 | the Free Software Foundation; either version 2 of the License, or | 
|  | 11 | (at your option) any later version. | 
|  | 12 |  | 
|  | 13 | This program is distributed in the hope that it will be useful, | 
|  | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|  | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|  | 16 | GNU General Public License for more details. | 
|  | 17 |  | 
|  | 18 | You should have received a copy of the GNU General Public License | 
|  | 19 | along with this program; see the file COPYING.  If not, write to | 
|  | 20 | the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor, | 
|  | 21 | Boston, MA 02110-1301, USA. | 
|  | 22 |  | 
|  | 23 | */ | 
|  | 24 |  | 
| Michael Buesch | 8e9f752 | 2007-09-27 21:35:34 +0200 | [diff] [blame] | 25 | #include "b43.h" | 
| Larry Finger | 1a8d122 | 2007-12-14 13:59:11 +0100 | [diff] [blame] | 26 |  | 
| Michael Buesch | 8e9f752 | 2007-09-27 21:35:34 +0200 | [diff] [blame] | 27 |  | 
| Michael Buesch | 42bb4cd | 2007-09-28 14:22:33 +0200 | [diff] [blame] | 28 | /* Returns TRUE, if the radio is enabled in hardware. */ | 
| Johannes Berg | f41f3f3 | 2009-06-07 12:30:34 -0500 | [diff] [blame] | 29 | bool b43_is_hw_radio_enabled(struct b43_wldev *dev) | 
| Michael Buesch | 8e9f752 | 2007-09-27 21:35:34 +0200 | [diff] [blame] | 30 | { | 
| Larry Finger | 692e565 | 2009-09-21 17:59:27 -0500 | [diff] [blame] | 31 | if (dev->phy.rev >= 3 || dev->phy.type == B43_PHYTYPE_LP) { | 
| Michael Buesch | 42bb4cd | 2007-09-28 14:22:33 +0200 | [diff] [blame] | 32 | if (!(b43_read32(dev, B43_MMIO_RADIO_HWENABLED_HI) | 
|  | 33 | & B43_MMIO_RADIO_HWENABLED_HI_MASK)) | 
|  | 34 | return 1; | 
|  | 35 | } else { | 
| Larry Finger | d50bae3 | 2009-10-16 10:18:09 -0500 | [diff] [blame] | 36 | if (b43_status(dev) >= B43_STAT_STARTED && | 
|  | 37 | b43_read16(dev, B43_MMIO_RADIO_HWENABLED_LO) | 
| Michael Buesch | 42bb4cd | 2007-09-28 14:22:33 +0200 | [diff] [blame] | 38 | & B43_MMIO_RADIO_HWENABLED_LO_MASK) | 
|  | 39 | return 1; | 
| Michael Buesch | 8e9f752 | 2007-09-27 21:35:34 +0200 | [diff] [blame] | 40 | } | 
| Michael Buesch | 42bb4cd | 2007-09-28 14:22:33 +0200 | [diff] [blame] | 41 | return 0; | 
| Michael Buesch | 8e9f752 | 2007-09-27 21:35:34 +0200 | [diff] [blame] | 42 | } | 
|  | 43 |  | 
| Michael Buesch | 42bb4cd | 2007-09-28 14:22:33 +0200 | [diff] [blame] | 44 | /* The poll callback for the hardware button. */ | 
| Johannes Berg | f41f3f3 | 2009-06-07 12:30:34 -0500 | [diff] [blame] | 45 | void b43_rfkill_poll(struct ieee80211_hw *hw) | 
| Michael Buesch | 8e9f752 | 2007-09-27 21:35:34 +0200 | [diff] [blame] | 46 | { | 
| Johannes Berg | f41f3f3 | 2009-06-07 12:30:34 -0500 | [diff] [blame] | 47 | struct b43_wl *wl = hw_to_b43_wl(hw); | 
|  | 48 | struct b43_wldev *dev = wl->current_dev; | 
|  | 49 | struct ssb_bus *bus = dev->dev->bus; | 
| Michael Buesch | 42bb4cd | 2007-09-28 14:22:33 +0200 | [diff] [blame] | 50 | bool enabled; | 
| Johannes Berg | f41f3f3 | 2009-06-07 12:30:34 -0500 | [diff] [blame] | 51 | bool brought_up = false; | 
| Michael Buesch | 8e9f752 | 2007-09-27 21:35:34 +0200 | [diff] [blame] | 52 |  | 
| Michael Buesch | 42bb4cd | 2007-09-28 14:22:33 +0200 | [diff] [blame] | 53 | mutex_lock(&wl->mutex); | 
| Larry Finger | 1a8d122 | 2007-12-14 13:59:11 +0100 | [diff] [blame] | 54 | if (unlikely(b43_status(dev) < B43_STAT_INITIALIZED)) { | 
| Johannes Berg | f41f3f3 | 2009-06-07 12:30:34 -0500 | [diff] [blame] | 55 | if (ssb_bus_powerup(bus, 0)) { | 
|  | 56 | mutex_unlock(&wl->mutex); | 
|  | 57 | return; | 
|  | 58 | } | 
|  | 59 | ssb_device_enable(dev->dev, 0); | 
|  | 60 | brought_up = true; | 
| Larry Finger | 1a8d122 | 2007-12-14 13:59:11 +0100 | [diff] [blame] | 61 | } | 
| Johannes Berg | f41f3f3 | 2009-06-07 12:30:34 -0500 | [diff] [blame] | 62 |  | 
| Michael Buesch | 42bb4cd | 2007-09-28 14:22:33 +0200 | [diff] [blame] | 63 | enabled = b43_is_hw_radio_enabled(dev); | 
| Johannes Berg | f41f3f3 | 2009-06-07 12:30:34 -0500 | [diff] [blame] | 64 |  | 
| Michael Buesch | 42bb4cd | 2007-09-28 14:22:33 +0200 | [diff] [blame] | 65 | if (unlikely(enabled != dev->radio_hw_enable)) { | 
|  | 66 | dev->radio_hw_enable = enabled; | 
|  | 67 | b43info(wl, "Radio hardware status changed to %s\n", | 
|  | 68 | enabled ? "ENABLED" : "DISABLED"); | 
| Johannes Berg | f41f3f3 | 2009-06-07 12:30:34 -0500 | [diff] [blame] | 69 | wiphy_rfkill_set_hw_state(hw->wiphy, !enabled); | 
| Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 70 | if (enabled != dev->phy.radio_on) | 
|  | 71 | b43_software_rfkill(dev, !enabled); | 
| Michael Buesch | 35c7e66 | 2007-11-03 14:34:32 +0100 | [diff] [blame] | 72 | } | 
| Johannes Berg | f41f3f3 | 2009-06-07 12:30:34 -0500 | [diff] [blame] | 73 |  | 
|  | 74 | if (brought_up) { | 
|  | 75 | ssb_device_disable(dev->dev, 0); | 
|  | 76 | ssb_bus_may_powerdown(bus); | 
|  | 77 | } | 
|  | 78 |  | 
| Michael Buesch | 35c7e66 | 2007-11-03 14:34:32 +0100 | [diff] [blame] | 79 | mutex_unlock(&wl->mutex); | 
| Michael Buesch | 8e9f752 | 2007-09-27 21:35:34 +0200 | [diff] [blame] | 80 | } |