| Larry Finger | 93bb7f3 | 2007-10-10 22:44:22 -0500 | [diff] [blame] | 1 | /* | 
|  | 2 |  | 
| Larry Finger | 6be5083 | 2007-10-10 22:48:17 -0500 | [diff] [blame] | 3 | Broadcom B43 wireless driver | 
| Larry Finger | 93bb7f3 | 2007-10-10 22:44:22 -0500 | [diff] [blame] | 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 |  | 
| Larry Finger | 93bb7f3 | 2007-10-10 22:44:22 -0500 | [diff] [blame] | 25 | #include "radio.h" | 
|  | 26 | #include "b43legacy.h" | 
|  | 27 |  | 
|  | 28 |  | 
| Larry Finger | 6be5083 | 2007-10-10 22:48:17 -0500 | [diff] [blame] | 29 | /* Returns TRUE, if the radio is enabled in hardware. */ | 
| Johannes Berg | f41f3f3 | 2009-06-07 12:30:34 -0500 | [diff] [blame] | 30 | bool b43legacy_is_hw_radio_enabled(struct b43legacy_wldev *dev) | 
| Larry Finger | 93bb7f3 | 2007-10-10 22:44:22 -0500 | [diff] [blame] | 31 | { | 
| Rafał Miłecki | 21e731a | 2010-11-03 21:36:12 +0100 | [diff] [blame] | 32 | if (dev->dev->id.revision >= 3) { | 
| Larry Finger | 6be5083 | 2007-10-10 22:48:17 -0500 | [diff] [blame] | 33 | if (!(b43legacy_read32(dev, B43legacy_MMIO_RADIO_HWENABLED_HI) | 
|  | 34 | & B43legacy_MMIO_RADIO_HWENABLED_HI_MASK)) | 
|  | 35 | return 1; | 
|  | 36 | } else { | 
| Larry Finger | 316a4d9 | 2009-11-23 18:42:36 -0600 | [diff] [blame] | 37 | /* To prevent CPU fault on PPC, do not read a register | 
|  | 38 | * unless the interface is started; however, on resume | 
|  | 39 | * for hibernation, this routine is entered early. When | 
|  | 40 | * that happens, unconditionally return TRUE. | 
|  | 41 | */ | 
|  | 42 | if (b43legacy_status(dev) < B43legacy_STAT_STARTED) | 
|  | 43 | return 1; | 
| Larry Finger | 6be5083 | 2007-10-10 22:48:17 -0500 | [diff] [blame] | 44 | if (b43legacy_read16(dev, B43legacy_MMIO_RADIO_HWENABLED_LO) | 
|  | 45 | & B43legacy_MMIO_RADIO_HWENABLED_LO_MASK) | 
|  | 46 | return 1; | 
| Larry Finger | 93bb7f3 | 2007-10-10 22:44:22 -0500 | [diff] [blame] | 47 | } | 
| Larry Finger | 6be5083 | 2007-10-10 22:48:17 -0500 | [diff] [blame] | 48 | return 0; | 
| Larry Finger | 93bb7f3 | 2007-10-10 22:44:22 -0500 | [diff] [blame] | 49 | } | 
|  | 50 |  | 
| Larry Finger | 6be5083 | 2007-10-10 22:48:17 -0500 | [diff] [blame] | 51 | /* The poll callback for the hardware button. */ | 
| Johannes Berg | f41f3f3 | 2009-06-07 12:30:34 -0500 | [diff] [blame] | 52 | void b43legacy_rfkill_poll(struct ieee80211_hw *hw) | 
| Larry Finger | 93bb7f3 | 2007-10-10 22:44:22 -0500 | [diff] [blame] | 53 | { | 
| Johannes Berg | f41f3f3 | 2009-06-07 12:30:34 -0500 | [diff] [blame] | 54 | struct b43legacy_wl *wl = hw_to_b43legacy_wl(hw); | 
|  | 55 | struct b43legacy_wldev *dev = wl->current_dev; | 
|  | 56 | struct ssb_bus *bus = dev->dev->bus; | 
| Larry Finger | 6be5083 | 2007-10-10 22:48:17 -0500 | [diff] [blame] | 57 | bool enabled; | 
| Johannes Berg | f41f3f3 | 2009-06-07 12:30:34 -0500 | [diff] [blame] | 58 | bool brought_up = false; | 
| Larry Finger | 93bb7f3 | 2007-10-10 22:44:22 -0500 | [diff] [blame] | 59 |  | 
| Larry Finger | 6be5083 | 2007-10-10 22:48:17 -0500 | [diff] [blame] | 60 | mutex_lock(&wl->mutex); | 
| Larry Finger | 4ad36d7 | 2007-12-16 19:21:06 +0100 | [diff] [blame] | 61 | if (unlikely(b43legacy_status(dev) < B43legacy_STAT_INITIALIZED)) { | 
| Johannes Berg | f41f3f3 | 2009-06-07 12:30:34 -0500 | [diff] [blame] | 62 | if (ssb_bus_powerup(bus, 0)) { | 
|  | 63 | mutex_unlock(&wl->mutex); | 
|  | 64 | return; | 
|  | 65 | } | 
|  | 66 | ssb_device_enable(dev->dev, 0); | 
|  | 67 | brought_up = true; | 
| Larry Finger | 4ad36d7 | 2007-12-16 19:21:06 +0100 | [diff] [blame] | 68 | } | 
| Johannes Berg | f41f3f3 | 2009-06-07 12:30:34 -0500 | [diff] [blame] | 69 |  | 
| Larry Finger | 6be5083 | 2007-10-10 22:48:17 -0500 | [diff] [blame] | 70 | enabled = b43legacy_is_hw_radio_enabled(dev); | 
| Johannes Berg | f41f3f3 | 2009-06-07 12:30:34 -0500 | [diff] [blame] | 71 |  | 
| Larry Finger | 6be5083 | 2007-10-10 22:48:17 -0500 | [diff] [blame] | 72 | if (unlikely(enabled != dev->radio_hw_enable)) { | 
|  | 73 | dev->radio_hw_enable = enabled; | 
|  | 74 | b43legacyinfo(wl, "Radio hardware status changed to %s\n", | 
|  | 75 | enabled ? "ENABLED" : "DISABLED"); | 
| Johannes Berg | f41f3f3 | 2009-06-07 12:30:34 -0500 | [diff] [blame] | 76 | wiphy_rfkill_set_hw_state(hw->wiphy, !enabled); | 
| Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 77 | if (enabled != dev->phy.radio_on) { | 
|  | 78 | if (enabled) | 
|  | 79 | b43legacy_radio_turn_on(dev); | 
|  | 80 | else | 
|  | 81 | b43legacy_radio_turn_off(dev, 0); | 
|  | 82 | } | 
| Stefano Brivio | db9683f | 2007-11-06 22:48:45 +0100 | [diff] [blame] | 83 | } | 
| Larry Finger | 93bb7f3 | 2007-10-10 22:44:22 -0500 | [diff] [blame] | 84 |  | 
| Johannes Berg | f41f3f3 | 2009-06-07 12:30:34 -0500 | [diff] [blame] | 85 | if (brought_up) { | 
|  | 86 | ssb_device_disable(dev->dev, 0); | 
|  | 87 | ssb_bus_may_powerdown(bus); | 
| Larry Finger | 93bb7f3 | 2007-10-10 22:44:22 -0500 | [diff] [blame] | 88 | } | 
|  | 89 |  | 
| Larry Finger | 93bb7f3 | 2007-10-10 22:44:22 -0500 | [diff] [blame] | 90 | mutex_unlock(&wl->mutex); | 
| Larry Finger | 93bb7f3 | 2007-10-10 22:44:22 -0500 | [diff] [blame] | 91 | } |