Loading...
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3
4 Broadcom B43 wireless driver
5 RFKILL support
6
7 Copyright (c) 2007 Michael Buesch <m@bues.ch>
8
9
10*/
11
12#include "b43.h"
13
14
15/* Returns TRUE, if the radio is enabled in hardware. */
16bool b43_is_hw_radio_enabled(struct b43_wldev *dev)
17{
18 return !(b43_read32(dev, B43_MMIO_RADIO_HWENABLED_HI)
19 & B43_MMIO_RADIO_HWENABLED_HI_MASK);
20}
21
22/* The poll callback for the hardware button. */
23void b43_rfkill_poll(struct ieee80211_hw *hw)
24{
25 struct b43_wl *wl = hw_to_b43_wl(hw);
26 struct b43_wldev *dev = wl->current_dev;
27 bool enabled;
28 bool brought_up = false;
29
30 mutex_lock(&wl->mutex);
31 if (unlikely(b43_status(dev) < B43_STAT_INITIALIZED)) {
32 if (b43_bus_powerup(dev, 0)) {
33 mutex_unlock(&wl->mutex);
34 return;
35 }
36 b43_device_enable(dev, 0);
37 brought_up = true;
38 }
39
40 enabled = b43_is_hw_radio_enabled(dev);
41
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");
46 wiphy_rfkill_set_hw_state(hw->wiphy, !enabled);
47 if (enabled != dev->phy.radio_on)
48 b43_software_rfkill(dev, !enabled);
49 }
50
51 if (brought_up) {
52 b43_device_disable(dev, 0);
53 b43_bus_may_powerdown(dev);
54 }
55
56 mutex_unlock(&wl->mutex);
57}
1/*
2
3 Broadcom B43 wireless driver
4 RFKILL support
5
6 Copyright (c) 2007 Michael Buesch <m@bues.ch>
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
25#include "b43.h"
26
27
28/* Returns TRUE, if the radio is enabled in hardware. */
29bool b43_is_hw_radio_enabled(struct b43_wldev *dev)
30{
31 return !(b43_read32(dev, B43_MMIO_RADIO_HWENABLED_HI)
32 & B43_MMIO_RADIO_HWENABLED_HI_MASK);
33}
34
35/* The poll callback for the hardware button. */
36void b43_rfkill_poll(struct ieee80211_hw *hw)
37{
38 struct b43_wl *wl = hw_to_b43_wl(hw);
39 struct b43_wldev *dev = wl->current_dev;
40 bool enabled;
41 bool brought_up = false;
42
43 mutex_lock(&wl->mutex);
44 if (unlikely(b43_status(dev) < B43_STAT_INITIALIZED)) {
45 if (b43_bus_powerup(dev, 0)) {
46 mutex_unlock(&wl->mutex);
47 return;
48 }
49 b43_device_enable(dev, 0);
50 brought_up = true;
51 }
52
53 enabled = b43_is_hw_radio_enabled(dev);
54
55 if (unlikely(enabled != dev->radio_hw_enable)) {
56 dev->radio_hw_enable = enabled;
57 b43info(wl, "Radio hardware status changed to %s\n",
58 enabled ? "ENABLED" : "DISABLED");
59 wiphy_rfkill_set_hw_state(hw->wiphy, !enabled);
60 if (enabled != dev->phy.radio_on)
61 b43_software_rfkill(dev, !enabled);
62 }
63
64 if (brought_up) {
65 b43_device_disable(dev, 0);
66 b43_bus_may_powerdown(dev);
67 }
68
69 mutex_unlock(&wl->mutex);
70}