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 * This is called without locking. */
66 static int b43_rfkill_soft_toggle(void *data, enum rfkill_state state)
68 struct b43_wldev *dev = data;
69 struct b43_wl *wl = dev->wl;
72 mutex_lock(&wl->mutex);
73 if (b43_status(dev) < B43_STAT_INITIALIZED)
78 if (!dev->radio_hw_enable) {
79 /* No luck. We can't toggle the hardware RF-kill
80 * button from software. */
84 if (!dev->phy.radio_on)
85 b43_radio_turn_on(dev);
87 case RFKILL_STATE_OFF:
88 if (dev->phy.radio_on)
89 b43_radio_turn_off(dev, 0);
94 mutex_unlock(&wl->mutex);
99 char * b43_rfkill_led_name(struct b43_wldev *dev)
101 struct b43_wl *wl = dev->wl;
103 if (!wl->rfkill.rfkill)
105 return rfkill_get_led_name(wl->rfkill.rfkill);
108 void b43_rfkill_init(struct b43_wldev *dev)
110 struct b43_wl *wl = dev->wl;
111 struct b43_rfkill *rfk = &(wl->rfkill);
115 err = rfkill_register(rfk->rfkill);
117 b43warn(wl, "Failed to register RF-kill button\n");
122 err = input_register_polled_device(rfk->poll_dev);
124 b43warn(wl, "Failed to register RF-kill polldev\n");
125 goto err_free_polldev;
131 rfkill_free(rfk->rfkill);
134 input_free_polled_device(rfk->poll_dev);
135 rfk->poll_dev = NULL;
138 void b43_rfkill_exit(struct b43_wldev *dev)
140 struct b43_rfkill *rfk = &(dev->wl->rfkill);
143 input_unregister_polled_device(rfk->poll_dev);
145 rfkill_unregister(rfk->rfkill);
148 void b43_rfkill_alloc(struct b43_wldev *dev)
150 struct b43_wl *wl = dev->wl;
151 struct b43_rfkill *rfk = &(wl->rfkill);
153 snprintf(rfk->name, sizeof(rfk->name),
154 "b43-%s", wiphy_name(wl->hw->wiphy));
156 rfk->rfkill = rfkill_allocate(dev->dev->dev, RFKILL_TYPE_WLAN);
158 b43warn(wl, "Failed to allocate RF-kill button\n");
161 rfk->rfkill->name = rfk->name;
162 rfk->rfkill->state = RFKILL_STATE_ON;
163 rfk->rfkill->data = dev;
164 rfk->rfkill->toggle_radio = b43_rfkill_soft_toggle;
165 rfk->rfkill->user_claim_unsupported = 1;
167 rfk->poll_dev = input_allocate_polled_device();
169 rfk->poll_dev->private = dev;
170 rfk->poll_dev->poll = b43_rfkill_poll;
171 rfk->poll_dev->poll_interval = 1000; /* msecs */
173 b43warn(wl, "Failed to allocate RF-kill polldev\n");
176 void b43_rfkill_free(struct b43_wldev *dev)
178 struct b43_rfkill *rfk = &(dev->wl->rfkill);
180 input_free_polled_device(rfk->poll_dev);
181 rfk->poll_dev = NULL;
182 rfkill_free(rfk->rfkill);