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.
29 /* Returns TRUE, if the radio is enabled in hardware. */
30 static bool b43_is_hw_radio_enabled(struct b43_wldev *dev)
32 if (dev->phy.rev >= 3) {
33 if (!(b43_read32(dev, B43_MMIO_RADIO_HWENABLED_HI)
34 & B43_MMIO_RADIO_HWENABLED_HI_MASK))
37 if (b43_read16(dev, B43_MMIO_RADIO_HWENABLED_LO)
38 & B43_MMIO_RADIO_HWENABLED_LO_MASK)
44 /* The poll callback for the hardware button. */
45 static void b43_rfkill_poll(struct input_polled_dev *poll_dev)
47 struct b43_wldev *dev = poll_dev->private;
48 struct b43_wl *wl = dev->wl;
51 mutex_lock(&wl->mutex);
52 B43_WARN_ON(b43_status(dev) < B43_STAT_INITIALIZED);
53 enabled = b43_is_hw_radio_enabled(dev);
54 if (unlikely(enabled != dev->radio_hw_enable)) {
55 dev->radio_hw_enable = enabled;
56 b43info(wl, "Radio hardware status changed to %s\n",
57 enabled ? "ENABLED" : "DISABLED");
58 mutex_unlock(&wl->mutex);
59 input_report_key(poll_dev->input, KEY_WLAN, enabled);
61 mutex_unlock(&wl->mutex);
64 /* Called when the RFKILL toggled in software. */
65 static int b43_rfkill_soft_toggle(void *data, enum rfkill_state state)
67 struct b43_wldev *dev = data;
68 struct b43_wl *wl = dev->wl;
71 /* When RFKILL is registered, it will call back into this callback.
72 * wl->mutex will already be locked when this happens.
73 * So first trylock. On contention check if we are in initialization.
74 * Silently return if that happens to avoid a deadlock. */
75 if (mutex_trylock(&wl->mutex) == 0) {
76 if (b43_status(dev) < B43_STAT_INITIALIZED)
78 mutex_lock(&wl->mutex);
80 if (b43_status(dev) < B43_STAT_INITIALIZED)
85 if (!dev->radio_hw_enable) {
86 /* No luck. We can't toggle the hardware RF-kill
87 * button from software. */
91 if (!dev->phy.radio_on)
92 b43_radio_turn_on(dev);
94 case RFKILL_STATE_OFF:
95 if (dev->phy.radio_on)
96 b43_radio_turn_off(dev, 0);
100 mutex_unlock(&wl->mutex);
105 char * b43_rfkill_led_name(struct b43_wldev *dev)
107 struct b43_wl *wl = dev->wl;
109 if (!wl->rfkill.rfkill)
111 return rfkill_get_led_name(wl->rfkill.rfkill);
114 void b43_rfkill_init(struct b43_wldev *dev)
116 struct b43_wl *wl = dev->wl;
117 struct b43_rfkill *rfk = &(wl->rfkill);
121 err = rfkill_register(rfk->rfkill);
123 b43warn(wl, "Failed to register RF-kill button\n");
128 err = input_register_polled_device(rfk->poll_dev);
130 b43warn(wl, "Failed to register RF-kill polldev\n");
131 goto err_free_polldev;
137 rfkill_free(rfk->rfkill);
140 input_free_polled_device(rfk->poll_dev);
141 rfk->poll_dev = NULL;
144 void b43_rfkill_exit(struct b43_wldev *dev)
146 struct b43_rfkill *rfk = &(dev->wl->rfkill);
149 input_unregister_polled_device(rfk->poll_dev);
151 rfkill_unregister(rfk->rfkill);
154 void b43_rfkill_alloc(struct b43_wldev *dev)
156 struct b43_wl *wl = dev->wl;
157 struct b43_rfkill *rfk = &(wl->rfkill);
159 snprintf(rfk->name, sizeof(rfk->name),
160 "b43-%s", wiphy_name(wl->hw->wiphy));
162 rfk->rfkill = rfkill_allocate(dev->dev->dev, RFKILL_TYPE_WLAN);
164 b43warn(wl, "Failed to allocate RF-kill button\n");
167 rfk->rfkill->name = rfk->name;
168 rfk->rfkill->state = RFKILL_STATE_ON;
169 rfk->rfkill->data = dev;
170 rfk->rfkill->toggle_radio = b43_rfkill_soft_toggle;
171 rfk->rfkill->user_claim_unsupported = 1;
173 rfk->poll_dev = input_allocate_polled_device();
175 rfk->poll_dev->private = dev;
176 rfk->poll_dev->poll = b43_rfkill_poll;
177 rfk->poll_dev->poll_interval = 1000; /* msecs */
179 b43warn(wl, "Failed to allocate RF-kill polldev\n");
182 void b43_rfkill_free(struct b43_wldev *dev)
184 struct b43_rfkill *rfk = &(dev->wl->rfkill);
186 input_free_polled_device(rfk->poll_dev);
187 rfk->poll_dev = NULL;
188 rfkill_free(rfk->rfkill);