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 static void b43_notify_rfkill_press(struct work_struct *work)
31 struct b43_rfkill *rfk = container_of(work, struct b43_rfkill,
33 struct b43_wl *wl = container_of(rfk, struct b43_wl, rfkill);
34 struct b43_wldev *dev;
35 enum rfkill_state state;
37 mutex_lock(&wl->mutex);
38 dev = wl->current_dev;
39 if (b43_status(dev) < B43_STAT_INITIALIZED) {
40 mutex_unlock(&wl->mutex);
43 if (dev->radio_hw_enable)
44 state = RFKILL_STATE_ON;
46 state = RFKILL_STATE_OFF;
47 b43info(wl, "Radio hardware status changed to %s\n",
48 dev->radio_hw_enable ? "ENABLED" : "DISABLED");
49 mutex_unlock(&wl->mutex);
52 /* Be careful. This calls back into the software toggle routines.
53 * So we must unlock before calling. */
54 rfkill_switch_all(rfk->rfkill->type, state);
58 /* Called when the RFKILL toggled in hardware.
59 * This is called with the mutex locked. */
60 void b43_rfkill_toggled(struct b43_wldev *dev, bool on)
62 struct b43_wl *wl = dev->wl;
64 B43_WARN_ON(b43_status(dev) < B43_STAT_INITIALIZED);
65 /* Update the RF status asynchronously, as rfkill will
66 * call back into the software toggle handler.
67 * This would deadlock if done synchronously. */
68 queue_work(wl->hw->workqueue, &wl->rfkill.notify_work);
71 /* Called when the RFKILL toggled in software.
72 * This is called without locking. */
73 static int b43_rfkill_soft_toggle(void *data, enum rfkill_state state)
75 struct b43_wldev *dev = data;
76 struct b43_wl *wl = dev->wl;
79 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);
101 mutex_unlock(&wl->mutex);
106 char * b43_rfkill_led_name(struct b43_wldev *dev)
108 struct b43_wl *wl = dev->wl;
110 if (!wl->rfkill.rfkill)
112 return rfkill_get_led_name(wl->rfkill.rfkill);
115 void b43_rfkill_init(struct b43_wldev *dev)
117 struct b43_wl *wl = dev->wl;
118 struct b43_rfkill *rfk = &(wl->rfkill);
121 snprintf(rfk->name, sizeof(rfk->name),
122 "b43-%s", wiphy_name(wl->hw->wiphy));
123 rfk->rfkill = rfkill_allocate(dev->dev->dev, RFKILL_TYPE_WLAN);
126 rfk->rfkill->name = rfk->name;
127 rfk->rfkill->state = RFKILL_STATE_ON;
128 rfk->rfkill->data = dev;
129 rfk->rfkill->toggle_radio = b43_rfkill_soft_toggle;
130 rfk->rfkill->user_claim_unsupported = 1;
132 INIT_WORK(&rfk->notify_work, b43_notify_rfkill_press);
134 err = rfkill_register(rfk->rfkill);
140 b43warn(dev->wl, "Failed to initialize the RF-kill button\n");
141 rfkill_free(rfk->rfkill);
145 void b43_rfkill_exit(struct b43_wldev *dev)
147 struct b43_rfkill *rfk = &(dev->wl->rfkill);
151 cancel_work_sync(&rfk->notify_work);
152 rfkill_unregister(rfk->rfkill);
153 rfkill_free(rfk->rfkill);