3 Broadcom B43 wireless driver
6 Copyright (c) 2007 Michael Buesch <mb@bu3sch.de>
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.
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.
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.
27 #include "b43legacy.h"
29 #include <linux/kmod.h>
32 /* Returns TRUE, if the radio is enabled in hardware. */
33 static bool b43legacy_is_hw_radio_enabled(struct b43legacy_wldev *dev)
35 if (dev->phy.rev >= 3) {
36 if (!(b43legacy_read32(dev, B43legacy_MMIO_RADIO_HWENABLED_HI)
37 & B43legacy_MMIO_RADIO_HWENABLED_HI_MASK))
40 if (b43legacy_read16(dev, B43legacy_MMIO_RADIO_HWENABLED_LO)
41 & B43legacy_MMIO_RADIO_HWENABLED_LO_MASK)
47 /* The poll callback for the hardware button. */
48 static void b43legacy_rfkill_poll(struct rfkill *rfkill, void *data)
50 struct b43legacy_wldev *dev = data;
51 struct b43legacy_wl *wl = dev->wl;
54 mutex_lock(&wl->mutex);
55 if (unlikely(b43legacy_status(dev) < B43legacy_STAT_INITIALIZED)) {
56 mutex_unlock(&wl->mutex);
59 enabled = b43legacy_is_hw_radio_enabled(dev);
60 if (unlikely(enabled != dev->radio_hw_enable)) {
61 dev->radio_hw_enable = enabled;
62 b43legacyinfo(wl, "Radio hardware status changed to %s\n",
63 enabled ? "ENABLED" : "DISABLED");
64 enabled = !rfkill_set_hw_state(rfkill, !enabled);
65 if (enabled != dev->phy.radio_on) {
67 b43legacy_radio_turn_on(dev);
69 b43legacy_radio_turn_off(dev, 0);
72 mutex_unlock(&wl->mutex);
75 /* Called when the RFKILL toggled in software.
76 * This is called without locking. */
77 static int b43legacy_rfkill_soft_set(void *data, bool blocked)
79 struct b43legacy_wldev *dev = data;
80 struct b43legacy_wl *wl = dev->wl;
83 if (!wl->rfkill.registered)
86 mutex_lock(&wl->mutex);
87 if (b43legacy_status(dev) < B43legacy_STAT_INITIALIZED)
90 if (!dev->radio_hw_enable)
93 if (!blocked != dev->phy.radio_on) {
95 b43legacy_radio_turn_on(dev);
97 b43legacy_radio_turn_off(dev, 0);
102 mutex_unlock(&wl->mutex);
106 const char *b43legacy_rfkill_led_name(struct b43legacy_wldev *dev)
108 struct b43legacy_rfkill *rfk = &(dev->wl->rfkill);
110 if (!rfk->registered)
112 return rfkill_get_led_trigger_name(rfk->rfkill);
115 static const struct rfkill_ops b43legacy_rfkill_ops = {
116 .set_block = b43legacy_rfkill_soft_set,
117 .poll = b43legacy_rfkill_poll,
120 void b43legacy_rfkill_init(struct b43legacy_wldev *dev)
122 struct b43legacy_wl *wl = dev->wl;
123 struct b43legacy_rfkill *rfk = &(wl->rfkill);
128 snprintf(rfk->name, sizeof(rfk->name),
129 "b43legacy-%s", wiphy_name(wl->hw->wiphy));
130 rfk->rfkill = rfkill_alloc(rfk->name,
133 &b43legacy_rfkill_ops, dev);
137 err = rfkill_register(rfk->rfkill);
145 rfkill_destroy(rfk->rfkill);
148 b43legacywarn(wl, "RF-kill button init failed\n");
151 void b43legacy_rfkill_exit(struct b43legacy_wldev *dev)
153 struct b43legacy_rfkill *rfk = &(dev->wl->rfkill);
155 if (!rfk->registered)
159 rfkill_unregister(rfk->rfkill);
160 rfkill_destroy(rfk->rfkill);