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"
30 /* Returns TRUE, if the radio is enabled in hardware. */
31 static bool b43legacy_is_hw_radio_enabled(struct b43legacy_wldev *dev)
33 if (dev->phy.rev >= 3) {
34 if (!(b43legacy_read32(dev, B43legacy_MMIO_RADIO_HWENABLED_HI)
35 & B43legacy_MMIO_RADIO_HWENABLED_HI_MASK))
38 if (b43legacy_read16(dev, B43legacy_MMIO_RADIO_HWENABLED_LO)
39 & B43legacy_MMIO_RADIO_HWENABLED_LO_MASK)
45 /* The poll callback for the hardware button. */
46 static void b43legacy_rfkill_poll(struct input_polled_dev *poll_dev)
48 struct b43legacy_wldev *dev = poll_dev->private;
49 struct b43legacy_wl *wl = dev->wl;
51 bool report_change = 0;
53 mutex_lock(&wl->mutex);
54 B43legacy_WARN_ON(b43legacy_status(dev) < B43legacy_STAT_INITIALIZED);
55 enabled = b43legacy_is_hw_radio_enabled(dev);
56 if (unlikely(enabled != dev->radio_hw_enable)) {
57 dev->radio_hw_enable = enabled;
59 b43legacyinfo(wl, "Radio hardware status changed to %s\n",
60 enabled ? "ENABLED" : "DISABLED");
62 mutex_unlock(&wl->mutex);
64 if (unlikely(report_change))
65 input_report_key(poll_dev->input, KEY_WLAN, enabled);
68 /* Called when the RFKILL toggled in software.
69 * This is called without locking. */
70 static int b43legacy_rfkill_soft_toggle(void *data, enum rfkill_state state)
72 struct b43legacy_wldev *dev = data;
73 struct b43legacy_wl *wl = dev->wl;
76 if (!wl->rfkill.registered)
79 mutex_lock(&wl->mutex);
80 B43legacy_WARN_ON(b43legacy_status(dev) < B43legacy_STAT_INITIALIZED);
83 if (!dev->radio_hw_enable) {
84 /* No luck. We can't toggle the hardware RF-kill
85 * button from software. */
89 if (!dev->phy.radio_on)
90 b43legacy_radio_turn_on(dev);
92 case RFKILL_STATE_OFF:
93 if (dev->phy.radio_on)
94 b43legacy_radio_turn_off(dev, 0);
99 mutex_unlock(&wl->mutex);
104 char *b43legacy_rfkill_led_name(struct b43legacy_wldev *dev)
106 struct b43legacy_wl *wl = dev->wl;
108 if (!wl->rfkill.rfkill)
110 return rfkill_get_led_name(wl->rfkill.rfkill);
113 void b43legacy_rfkill_init(struct b43legacy_wldev *dev)
115 struct b43legacy_wl *wl = dev->wl;
116 struct b43legacy_rfkill *rfk = &(wl->rfkill);
120 err = rfkill_register(rfk->rfkill);
122 b43legacywarn(wl, "Failed to register RF-kill button\n");
127 err = input_register_polled_device(rfk->poll_dev);
129 b43legacywarn(wl, "Failed to register RF-kill polldev\n");
130 goto err_free_polldev;
136 rfkill_free(rfk->rfkill);
139 input_free_polled_device(rfk->poll_dev);
140 rfk->poll_dev = NULL;
143 void b43legacy_rfkill_exit(struct b43legacy_wldev *dev)
145 struct b43legacy_rfkill *rfk = &(dev->wl->rfkill);
148 input_unregister_polled_device(rfk->poll_dev);
150 rfkill_unregister(rfk->rfkill);
153 void b43legacy_rfkill_alloc(struct b43legacy_wldev *dev)
155 struct b43legacy_wl *wl = dev->wl;
156 struct b43legacy_rfkill *rfk = &(wl->rfkill);
158 snprintf(rfk->name, sizeof(rfk->name),
159 "b43legacy-%s", wiphy_name(wl->hw->wiphy));
161 rfk->rfkill = rfkill_allocate(dev->dev->dev, RFKILL_TYPE_WLAN);
163 b43legacywarn(wl, "Failed to allocate RF-kill button\n");
166 rfk->rfkill->name = rfk->name;
167 rfk->rfkill->state = RFKILL_STATE_ON;
168 rfk->rfkill->data = dev;
169 rfk->rfkill->toggle_radio = b43legacy_rfkill_soft_toggle;
170 rfk->rfkill->user_claim_unsupported = 1;
172 rfk->poll_dev = input_allocate_polled_device();
174 rfk->poll_dev->private = dev;
175 rfk->poll_dev->poll = b43legacy_rfkill_poll;
176 rfk->poll_dev->poll_interval = 1000; /* msecs */
178 b43legacywarn(wl, "Failed to allocate RF-kill polldev\n");
181 void b43legacy_rfkill_free(struct b43legacy_wldev *dev)
183 struct b43legacy_rfkill *rfk = &(dev->wl->rfkill);
185 input_free_polled_device(rfk->poll_dev);
186 rfk->poll_dev = NULL;
187 rfkill_free(rfk->rfkill);