1*ca47d344SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2423e3ce3SKalle Valo /*
3423e3ce3SKalle Valo
4423e3ce3SKalle Valo Broadcom B43 wireless driver
5423e3ce3SKalle Valo RFKILL support
6423e3ce3SKalle Valo
7423e3ce3SKalle Valo Copyright (c) 2007 Michael Buesch <m@bues.ch>
8423e3ce3SKalle Valo
9423e3ce3SKalle Valo
10423e3ce3SKalle Valo */
11423e3ce3SKalle Valo
12423e3ce3SKalle Valo #include "radio.h"
13423e3ce3SKalle Valo #include "b43legacy.h"
14423e3ce3SKalle Valo
15423e3ce3SKalle Valo
16423e3ce3SKalle Valo /* Returns TRUE, if the radio is enabled in hardware. */
b43legacy_is_hw_radio_enabled(struct b43legacy_wldev * dev)17423e3ce3SKalle Valo bool b43legacy_is_hw_radio_enabled(struct b43legacy_wldev *dev)
18423e3ce3SKalle Valo {
19423e3ce3SKalle Valo if (dev->dev->id.revision >= 3) {
20423e3ce3SKalle Valo if (!(b43legacy_read32(dev, B43legacy_MMIO_RADIO_HWENABLED_HI)
21423e3ce3SKalle Valo & B43legacy_MMIO_RADIO_HWENABLED_HI_MASK))
22423e3ce3SKalle Valo return true;
23423e3ce3SKalle Valo } else {
24423e3ce3SKalle Valo /* To prevent CPU fault on PPC, do not read a register
25423e3ce3SKalle Valo * unless the interface is started; however, on resume
26423e3ce3SKalle Valo * for hibernation, this routine is entered early. When
27423e3ce3SKalle Valo * that happens, unconditionally return TRUE.
28423e3ce3SKalle Valo */
29423e3ce3SKalle Valo if (b43legacy_status(dev) < B43legacy_STAT_STARTED)
30423e3ce3SKalle Valo return true;
31423e3ce3SKalle Valo if (b43legacy_read16(dev, B43legacy_MMIO_RADIO_HWENABLED_LO)
32423e3ce3SKalle Valo & B43legacy_MMIO_RADIO_HWENABLED_LO_MASK)
33423e3ce3SKalle Valo return true;
34423e3ce3SKalle Valo }
35423e3ce3SKalle Valo return false;
36423e3ce3SKalle Valo }
37423e3ce3SKalle Valo
38423e3ce3SKalle Valo /* The poll callback for the hardware button. */
b43legacy_rfkill_poll(struct ieee80211_hw * hw)39423e3ce3SKalle Valo void b43legacy_rfkill_poll(struct ieee80211_hw *hw)
40423e3ce3SKalle Valo {
41423e3ce3SKalle Valo struct b43legacy_wl *wl = hw_to_b43legacy_wl(hw);
42423e3ce3SKalle Valo struct b43legacy_wldev *dev = wl->current_dev;
43423e3ce3SKalle Valo struct ssb_bus *bus = dev->dev->bus;
44423e3ce3SKalle Valo bool enabled;
45423e3ce3SKalle Valo bool brought_up = false;
46423e3ce3SKalle Valo
47423e3ce3SKalle Valo mutex_lock(&wl->mutex);
48423e3ce3SKalle Valo if (unlikely(b43legacy_status(dev) < B43legacy_STAT_INITIALIZED)) {
49423e3ce3SKalle Valo if (ssb_bus_powerup(bus, 0)) {
50423e3ce3SKalle Valo mutex_unlock(&wl->mutex);
51423e3ce3SKalle Valo return;
52423e3ce3SKalle Valo }
53423e3ce3SKalle Valo ssb_device_enable(dev->dev, 0);
54423e3ce3SKalle Valo brought_up = true;
55423e3ce3SKalle Valo }
56423e3ce3SKalle Valo
57423e3ce3SKalle Valo enabled = b43legacy_is_hw_radio_enabled(dev);
58423e3ce3SKalle Valo
59423e3ce3SKalle Valo if (unlikely(enabled != dev->radio_hw_enable)) {
60423e3ce3SKalle Valo dev->radio_hw_enable = enabled;
61423e3ce3SKalle Valo b43legacyinfo(wl, "Radio hardware status changed to %s\n",
62423e3ce3SKalle Valo enabled ? "ENABLED" : "DISABLED");
63423e3ce3SKalle Valo wiphy_rfkill_set_hw_state(hw->wiphy, !enabled);
64423e3ce3SKalle Valo if (enabled != dev->phy.radio_on) {
65423e3ce3SKalle Valo if (enabled)
66423e3ce3SKalle Valo b43legacy_radio_turn_on(dev);
67423e3ce3SKalle Valo else
68423e3ce3SKalle Valo b43legacy_radio_turn_off(dev, 0);
69423e3ce3SKalle Valo }
70423e3ce3SKalle Valo }
71423e3ce3SKalle Valo
72423e3ce3SKalle Valo if (brought_up) {
73423e3ce3SKalle Valo ssb_device_disable(dev->dev, 0);
74423e3ce3SKalle Valo ssb_bus_may_powerdown(bus);
75423e3ce3SKalle Valo }
76423e3ce3SKalle Valo
77423e3ce3SKalle Valo mutex_unlock(&wl->mutex);
78423e3ce3SKalle Valo }
79