Thomas Gleixner | ca47d34 | 2019-05-19 15:51:50 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Michael Buesch | 8e9f752 | 2007-09-27 21:35:34 +0200 | [diff] [blame] | 2 | /* |
3 | |||||
4 | Broadcom B43 wireless driver | ||||
5 | RFKILL support | ||||
6 | |||||
Michael Büsch | eb032b9 | 2011-07-04 20:50:05 +0200 | [diff] [blame] | 7 | Copyright (c) 2007 Michael Buesch <m@bues.ch> |
Michael Buesch | 8e9f752 | 2007-09-27 21:35:34 +0200 | [diff] [blame] | 8 | |
Michael Buesch | 8e9f752 | 2007-09-27 21:35:34 +0200 | [diff] [blame] | 9 | |
10 | */ | ||||
11 | |||||
Michael Buesch | 8e9f752 | 2007-09-27 21:35:34 +0200 | [diff] [blame] | 12 | #include "b43.h" |
Larry Finger | 1a8d1227 | 2007-12-14 13:59:11 +0100 | [diff] [blame] | 13 | |
Michael Buesch | 8e9f752 | 2007-09-27 21:35:34 +0200 | [diff] [blame] | 14 | |
Michael Buesch | 42bb4cd | 2007-09-28 14:22:33 +0200 | [diff] [blame] | 15 | /* Returns TRUE, if the radio is enabled in hardware. */ |
Johannes Berg | f41f3f3 | 2009-06-07 12:30:34 -0500 | [diff] [blame] | 16 | bool b43_is_hw_radio_enabled(struct b43_wldev *dev) |
Michael Buesch | 8e9f752 | 2007-09-27 21:35:34 +0200 | [diff] [blame] | 17 | { |
Rafał Miłecki | 8ce4699 | 2010-11-17 22:14:37 +0100 | [diff] [blame] | 18 | return !(b43_read32(dev, B43_MMIO_RADIO_HWENABLED_HI) |
19 | & B43_MMIO_RADIO_HWENABLED_HI_MASK); | ||||
Michael Buesch | 8e9f752 | 2007-09-27 21:35:34 +0200 | [diff] [blame] | 20 | } |
21 | |||||
Michael Buesch | 42bb4cd | 2007-09-28 14:22:33 +0200 | [diff] [blame] | 22 | /* The poll callback for the hardware button. */ |
Johannes Berg | f41f3f3 | 2009-06-07 12:30:34 -0500 | [diff] [blame] | 23 | void b43_rfkill_poll(struct ieee80211_hw *hw) |
Michael Buesch | 8e9f752 | 2007-09-27 21:35:34 +0200 | [diff] [blame] | 24 | { |
Johannes Berg | f41f3f3 | 2009-06-07 12:30:34 -0500 | [diff] [blame] | 25 | struct b43_wl *wl = hw_to_b43_wl(hw); |
26 | struct b43_wldev *dev = wl->current_dev; | ||||
Michael Buesch | 42bb4cd | 2007-09-28 14:22:33 +0200 | [diff] [blame] | 27 | bool enabled; |
Johannes Berg | f41f3f3 | 2009-06-07 12:30:34 -0500 | [diff] [blame] | 28 | bool brought_up = false; |
Michael Buesch | 8e9f752 | 2007-09-27 21:35:34 +0200 | [diff] [blame] | 29 | |
Michael Buesch | 42bb4cd | 2007-09-28 14:22:33 +0200 | [diff] [blame] | 30 | mutex_lock(&wl->mutex); |
Larry Finger | 1a8d1227 | 2007-12-14 13:59:11 +0100 | [diff] [blame] | 31 | if (unlikely(b43_status(dev) < B43_STAT_INITIALIZED)) { |
Rafał Miłecki | 24ca39d | 2011-05-18 02:06:43 +0200 | [diff] [blame] | 32 | if (b43_bus_powerup(dev, 0)) { |
Johannes Berg | f41f3f3 | 2009-06-07 12:30:34 -0500 | [diff] [blame] | 33 | mutex_unlock(&wl->mutex); |
34 | return; | ||||
35 | } | ||||
Rafał Miłecki | 24ca39d | 2011-05-18 02:06:43 +0200 | [diff] [blame] | 36 | b43_device_enable(dev, 0); |
Johannes Berg | f41f3f3 | 2009-06-07 12:30:34 -0500 | [diff] [blame] | 37 | brought_up = true; |
Larry Finger | 1a8d1227 | 2007-12-14 13:59:11 +0100 | [diff] [blame] | 38 | } |
Johannes Berg | f41f3f3 | 2009-06-07 12:30:34 -0500 | [diff] [blame] | 39 | |
Michael Buesch | 42bb4cd | 2007-09-28 14:22:33 +0200 | [diff] [blame] | 40 | enabled = b43_is_hw_radio_enabled(dev); |
Johannes Berg | f41f3f3 | 2009-06-07 12:30:34 -0500 | [diff] [blame] | 41 | |
Michael Buesch | 42bb4cd | 2007-09-28 14:22:33 +0200 | [diff] [blame] | 42 | if (unlikely(enabled != dev->radio_hw_enable)) { |
43 | dev->radio_hw_enable = enabled; | ||||
44 | b43info(wl, "Radio hardware status changed to %s\n", | ||||
45 | enabled ? "ENABLED" : "DISABLED"); | ||||
Johannes Berg | f41f3f3 | 2009-06-07 12:30:34 -0500 | [diff] [blame] | 46 | wiphy_rfkill_set_hw_state(hw->wiphy, !enabled); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 47 | if (enabled != dev->phy.radio_on) |
48 | b43_software_rfkill(dev, !enabled); | ||||
Michael Buesch | 35c7e66 | 2007-11-03 14:34:32 +0100 | [diff] [blame] | 49 | } |
Johannes Berg | f41f3f3 | 2009-06-07 12:30:34 -0500 | [diff] [blame] | 50 | |
51 | if (brought_up) { | ||||
Rafał Miłecki | 24ca39d | 2011-05-18 02:06:43 +0200 | [diff] [blame] | 52 | b43_device_disable(dev, 0); |
53 | b43_bus_may_powerdown(dev); | ||||
Johannes Berg | f41f3f3 | 2009-06-07 12:30:34 -0500 | [diff] [blame] | 54 | } |
55 | |||||
Michael Buesch | 35c7e66 | 2007-11-03 14:34:32 +0100 | [diff] [blame] | 56 | mutex_unlock(&wl->mutex); |
Michael Buesch | 8e9f752 | 2007-09-27 21:35:34 +0200 | [diff] [blame] | 57 | } |