blob: acba64ffb3309f8c6426a0f93e06a344fac0cb62 [file] [log] [blame]
Michael Buesch8e9f7522007-09-27 21:35:34 +02001/*
2
3 Broadcom B43 wireless driver
4 RFKILL support
5
Michael Büscheb032b92011-07-04 20:50:05 +02006 Copyright (c) 2007 Michael Buesch <m@bues.ch>
Michael Buesch8e9f7522007-09-27 21:35:34 +02007
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
Michael Buesch8e9f7522007-09-27 21:35:34 +020025#include "b43.h"
Larry Finger1a8d1222007-12-14 13:59:11 +010026
Michael Buesch8e9f7522007-09-27 21:35:34 +020027
Michael Buesch42bb4cd2007-09-28 14:22:33 +020028/* Returns TRUE, if the radio is enabled in hardware. */
Johannes Bergf41f3f32009-06-07 12:30:34 -050029bool b43_is_hw_radio_enabled(struct b43_wldev *dev)
Michael Buesch8e9f7522007-09-27 21:35:34 +020030{
Rafał Miłecki8ce46992010-11-17 22:14:37 +010031 return !(b43_read32(dev, B43_MMIO_RADIO_HWENABLED_HI)
32 & B43_MMIO_RADIO_HWENABLED_HI_MASK);
Michael Buesch8e9f7522007-09-27 21:35:34 +020033}
34
Michael Buesch42bb4cd2007-09-28 14:22:33 +020035/* The poll callback for the hardware button. */
Johannes Bergf41f3f32009-06-07 12:30:34 -050036void b43_rfkill_poll(struct ieee80211_hw *hw)
Michael Buesch8e9f7522007-09-27 21:35:34 +020037{
Johannes Bergf41f3f32009-06-07 12:30:34 -050038 struct b43_wl *wl = hw_to_b43_wl(hw);
39 struct b43_wldev *dev = wl->current_dev;
Rafał Miłeckidedb1eb2011-05-14 00:04:38 +020040 struct ssb_bus *bus = dev->sdev->bus;
Michael Buesch42bb4cd2007-09-28 14:22:33 +020041 bool enabled;
Johannes Bergf41f3f32009-06-07 12:30:34 -050042 bool brought_up = false;
Michael Buesch8e9f7522007-09-27 21:35:34 +020043
Michael Buesch42bb4cd2007-09-28 14:22:33 +020044 mutex_lock(&wl->mutex);
Larry Finger1a8d1222007-12-14 13:59:11 +010045 if (unlikely(b43_status(dev) < B43_STAT_INITIALIZED)) {
Johannes Bergf41f3f32009-06-07 12:30:34 -050046 if (ssb_bus_powerup(bus, 0)) {
47 mutex_unlock(&wl->mutex);
48 return;
49 }
Rafał Miłeckidedb1eb2011-05-14 00:04:38 +020050 ssb_device_enable(dev->sdev, 0);
Johannes Bergf41f3f32009-06-07 12:30:34 -050051 brought_up = true;
Larry Finger1a8d1222007-12-14 13:59:11 +010052 }
Johannes Bergf41f3f32009-06-07 12:30:34 -050053
Michael Buesch42bb4cd2007-09-28 14:22:33 +020054 enabled = b43_is_hw_radio_enabled(dev);
Johannes Bergf41f3f32009-06-07 12:30:34 -050055
Michael Buesch42bb4cd2007-09-28 14:22:33 +020056 if (unlikely(enabled != dev->radio_hw_enable)) {
57 dev->radio_hw_enable = enabled;
58 b43info(wl, "Radio hardware status changed to %s\n",
59 enabled ? "ENABLED" : "DISABLED");
Johannes Bergf41f3f32009-06-07 12:30:34 -050060 wiphy_rfkill_set_hw_state(hw->wiphy, !enabled);
Johannes Berg19d337d2009-06-02 13:01:37 +020061 if (enabled != dev->phy.radio_on)
62 b43_software_rfkill(dev, !enabled);
Michael Buesch35c7e662007-11-03 14:34:32 +010063 }
Johannes Bergf41f3f32009-06-07 12:30:34 -050064
65 if (brought_up) {
Rafał Miłeckidedb1eb2011-05-14 00:04:38 +020066 ssb_device_disable(dev->sdev, 0);
Johannes Bergf41f3f32009-06-07 12:30:34 -050067 ssb_bus_may_powerdown(bus);
68 }
69
Michael Buesch35c7e662007-11-03 14:34:32 +010070 mutex_unlock(&wl->mutex);
Michael Buesch8e9f7522007-09-27 21:35:34 +020071}