Merge commit 'origin/master' into next
[pandora-kernel.git] / drivers / net / wireless / b43 / rfkill.c
1 /*
2
3   Broadcom B43 wireless driver
4   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
25 #include "b43.h"
26
27
28 /* Returns TRUE, if the radio is enabled in hardware. */
29 bool b43_is_hw_radio_enabled(struct b43_wldev *dev)
30 {
31         if (dev->phy.rev >= 3) {
32                 if (!(b43_read32(dev, B43_MMIO_RADIO_HWENABLED_HI)
33                       & B43_MMIO_RADIO_HWENABLED_HI_MASK))
34                         return 1;
35         } else {
36                 if (b43_read16(dev, B43_MMIO_RADIO_HWENABLED_LO)
37                     & B43_MMIO_RADIO_HWENABLED_LO_MASK)
38                         return 1;
39         }
40         return 0;
41 }
42
43 /* The poll callback for the hardware button. */
44 void b43_rfkill_poll(struct ieee80211_hw *hw)
45 {
46         struct b43_wl *wl = hw_to_b43_wl(hw);
47         struct b43_wldev *dev = wl->current_dev;
48         struct ssb_bus *bus = dev->dev->bus;
49         bool enabled;
50         bool brought_up = false;
51
52         mutex_lock(&wl->mutex);
53         if (unlikely(b43_status(dev) < B43_STAT_INITIALIZED)) {
54                 if (ssb_bus_powerup(bus, 0)) {
55                         mutex_unlock(&wl->mutex);
56                         return;
57                 }
58                 ssb_device_enable(dev->dev, 0);
59                 brought_up = true;
60         }
61
62         enabled = b43_is_hw_radio_enabled(dev);
63
64         if (unlikely(enabled != dev->radio_hw_enable)) {
65                 dev->radio_hw_enable = enabled;
66                 b43info(wl, "Radio hardware status changed to %s\n",
67                         enabled ? "ENABLED" : "DISABLED");
68                 wiphy_rfkill_set_hw_state(hw->wiphy, !enabled);
69                 if (enabled != dev->phy.radio_on)
70                         b43_software_rfkill(dev, !enabled);
71         }
72
73         if (brought_up) {
74                 ssb_device_disable(dev->dev, 0);
75                 ssb_bus_may_powerdown(bus);
76         }
77
78         mutex_unlock(&wl->mutex);
79 }