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 "phy_common.h"
29 #include <linux/kmod.h>
32 /* Returns TRUE, if the radio is enabled in hardware. */
33 static bool b43_is_hw_radio_enabled(struct b43_wldev *dev)
35 if (dev->phy.rev >= 3) {
36 if (!(b43_read32(dev, B43_MMIO_RADIO_HWENABLED_HI)
37 & B43_MMIO_RADIO_HWENABLED_HI_MASK))
40 if (b43_read16(dev, B43_MMIO_RADIO_HWENABLED_LO)
41 & B43_MMIO_RADIO_HWENABLED_LO_MASK)
47 /* The poll callback for the hardware button. */
48 static void b43_rfkill_poll(struct input_polled_dev *poll_dev)
50 struct b43_wldev *dev = poll_dev->private;
51 struct b43_wl *wl = dev->wl;
53 bool report_change = 0;
55 mutex_lock(&wl->mutex);
56 if (unlikely(b43_status(dev) < B43_STAT_INITIALIZED)) {
57 mutex_unlock(&wl->mutex);
60 enabled = b43_is_hw_radio_enabled(dev);
61 if (unlikely(enabled != dev->radio_hw_enable)) {
62 dev->radio_hw_enable = enabled;
64 b43info(wl, "Radio hardware status changed to %s\n",
65 enabled ? "ENABLED" : "DISABLED");
67 mutex_unlock(&wl->mutex);
69 /* send the radio switch event to the system - note both a key press
70 * and a release are required */
71 if (unlikely(report_change)) {
72 input_report_key(poll_dev->input, KEY_WLAN, 1);
73 input_report_key(poll_dev->input, KEY_WLAN, 0);
77 /* Called when the RFKILL toggled in software. */
78 static int b43_rfkill_soft_toggle(void *data, enum rfkill_state state)
80 struct b43_wldev *dev = data;
81 struct b43_wl *wl = dev->wl;
84 if (!wl->rfkill.registered)
87 mutex_lock(&wl->mutex);
88 if (b43_status(dev) < B43_STAT_INITIALIZED)
92 case RFKILL_STATE_UNBLOCKED:
93 if (!dev->radio_hw_enable) {
94 /* No luck. We can't toggle the hardware RF-kill
95 * button from software. */
99 if (!dev->phy.radio_on)
100 b43_software_rfkill(dev, state);
102 case RFKILL_STATE_SOFT_BLOCKED:
103 if (dev->phy.radio_on)
104 b43_software_rfkill(dev, state);
107 b43warn(wl, "Received unexpected rfkill state %d.\n", state);
111 mutex_unlock(&wl->mutex);
116 char * b43_rfkill_led_name(struct b43_wldev *dev)
118 struct b43_rfkill *rfk = &(dev->wl->rfkill);
120 if (!rfk->registered)
122 return rfkill_get_led_name(rfk->rfkill);
125 void b43_rfkill_init(struct b43_wldev *dev)
127 struct b43_wl *wl = dev->wl;
128 struct b43_rfkill *rfk = &(wl->rfkill);
133 rfk->rfkill = rfkill_allocate(dev->dev->dev, RFKILL_TYPE_WLAN);
136 snprintf(rfk->name, sizeof(rfk->name),
137 "b43-%s", wiphy_name(wl->hw->wiphy));
138 rfk->rfkill->name = rfk->name;
139 rfk->rfkill->state = RFKILL_STATE_UNBLOCKED;
140 rfk->rfkill->data = dev;
141 rfk->rfkill->toggle_radio = b43_rfkill_soft_toggle;
142 rfk->rfkill->user_claim_unsupported = 1;
144 rfk->poll_dev = input_allocate_polled_device();
145 if (!rfk->poll_dev) {
146 rfkill_free(rfk->rfkill);
150 rfk->poll_dev->private = dev;
151 rfk->poll_dev->poll = b43_rfkill_poll;
152 rfk->poll_dev->poll_interval = 1000; /* msecs */
154 rfk->poll_dev->input->name = rfk->name;
155 rfk->poll_dev->input->id.bustype = BUS_HOST;
156 rfk->poll_dev->input->id.vendor = dev->dev->bus->boardinfo.vendor;
157 rfk->poll_dev->input->evbit[0] = BIT(EV_KEY);
158 set_bit(KEY_WLAN, rfk->poll_dev->input->keybit);
160 err = rfkill_register(rfk->rfkill);
162 goto err_free_polldev;
164 #ifdef CONFIG_RFKILL_INPUT_MODULE
165 /* B43 RF-kill isn't useful without the rfkill-input subsystem.
166 * Try to load the module. */
167 err = request_module("rfkill-input");
169 b43warn(wl, "Failed to load the rfkill-input module. "
170 "The built-in radio LED will not work.\n");
171 #endif /* CONFIG_RFKILL_INPUT */
173 #if !defined(CONFIG_RFKILL_INPUT) && !defined(CONFIG_RFKILL_INPUT_MODULE)
174 b43warn(wl, "The rfkill-input subsystem is not available. "
175 "The built-in radio LED will not work.\n");
178 err = input_register_polled_device(rfk->poll_dev);
186 rfkill_unregister(rfk->rfkill);
188 input_free_polled_device(rfk->poll_dev);
189 rfk->poll_dev = NULL;
194 b43warn(wl, "RF-kill button init failed\n");
197 void b43_rfkill_exit(struct b43_wldev *dev)
199 struct b43_rfkill *rfk = &(dev->wl->rfkill);
201 if (!rfk->registered)
205 input_unregister_polled_device(rfk->poll_dev);
206 rfkill_unregister(rfk->rfkill);
207 input_free_polled_device(rfk->poll_dev);
208 rfk->poll_dev = NULL;