blob: 8783022db11e43e24ae12a641bd040a5aea38b07 [file] [log] [blame]
Larry Finger93bb7f32007-10-10 22:44:22 -05001/*
2
Larry Finger6be50832007-10-10 22:48:17 -05003 Broadcom B43 wireless driver
Larry Finger93bb7f32007-10-10 22:44:22 -05004 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 Finger93bb7f32007-10-10 22:44:22 -050025#include "radio.h"
26#include "b43legacy.h"
27
28
Larry Finger6be50832007-10-10 22:48:17 -050029/* Returns TRUE, if the radio is enabled in hardware. */
Johannes Bergf41f3f32009-06-07 12:30:34 -050030bool b43legacy_is_hw_radio_enabled(struct b43legacy_wldev *dev)
Larry Finger93bb7f32007-10-10 22:44:22 -050031{
Larry Finger6be50832007-10-10 22:48:17 -050032 if (dev->phy.rev >= 3) {
33 if (!(b43legacy_read32(dev, B43legacy_MMIO_RADIO_HWENABLED_HI)
34 & B43legacy_MMIO_RADIO_HWENABLED_HI_MASK))
35 return 1;
36 } else {
37 if (b43legacy_read16(dev, B43legacy_MMIO_RADIO_HWENABLED_LO)
38 & B43legacy_MMIO_RADIO_HWENABLED_LO_MASK)
39 return 1;
Larry Finger93bb7f32007-10-10 22:44:22 -050040 }
Larry Finger6be50832007-10-10 22:48:17 -050041 return 0;
Larry Finger93bb7f32007-10-10 22:44:22 -050042}
43
Larry Finger6be50832007-10-10 22:48:17 -050044/* The poll callback for the hardware button. */
Johannes Bergf41f3f32009-06-07 12:30:34 -050045void b43legacy_rfkill_poll(struct ieee80211_hw *hw)
Larry Finger93bb7f32007-10-10 22:44:22 -050046{
Johannes Bergf41f3f32009-06-07 12:30:34 -050047 struct b43legacy_wl *wl = hw_to_b43legacy_wl(hw);
48 struct b43legacy_wldev *dev = wl->current_dev;
49 struct ssb_bus *bus = dev->dev->bus;
Larry Finger6be50832007-10-10 22:48:17 -050050 bool enabled;
Johannes Bergf41f3f32009-06-07 12:30:34 -050051 bool brought_up = false;
Larry Finger93bb7f32007-10-10 22:44:22 -050052
Larry Finger6be50832007-10-10 22:48:17 -050053 mutex_lock(&wl->mutex);
Larry Finger4ad36d72007-12-16 19:21:06 +010054 if (unlikely(b43legacy_status(dev) < B43legacy_STAT_INITIALIZED)) {
Johannes Bergf41f3f32009-06-07 12:30:34 -050055 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 Finger4ad36d72007-12-16 19:21:06 +010061 }
Johannes Bergf41f3f32009-06-07 12:30:34 -050062
Larry Finger6be50832007-10-10 22:48:17 -050063 enabled = b43legacy_is_hw_radio_enabled(dev);
Johannes Bergf41f3f32009-06-07 12:30:34 -050064
Larry Finger6be50832007-10-10 22:48:17 -050065 if (unlikely(enabled != dev->radio_hw_enable)) {
66 dev->radio_hw_enable = enabled;
67 b43legacyinfo(wl, "Radio hardware status changed to %s\n",
68 enabled ? "ENABLED" : "DISABLED");
Johannes Bergf41f3f32009-06-07 12:30:34 -050069 wiphy_rfkill_set_hw_state(hw->wiphy, !enabled);
Johannes Berg19d337d2009-06-02 13:01:37 +020070 if (enabled != dev->phy.radio_on) {
71 if (enabled)
72 b43legacy_radio_turn_on(dev);
73 else
74 b43legacy_radio_turn_off(dev, 0);
75 }
Stefano Briviodb9683f2007-11-06 22:48:45 +010076 }
Larry Finger93bb7f32007-10-10 22:44:22 -050077
Johannes Bergf41f3f32009-06-07 12:30:34 -050078 if (brought_up) {
79 ssb_device_disable(dev->dev, 0);
80 ssb_bus_may_powerdown(bus);
Larry Finger93bb7f32007-10-10 22:44:22 -050081 }
82
Larry Finger93bb7f32007-10-10 22:44:22 -050083 mutex_unlock(&wl->mutex);
Larry Finger93bb7f32007-10-10 22:44:22 -050084}