3 Broadcom B43legacy 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 static void b43legacy_notify_rfkill_press(struct work_struct
*work
)
32 struct b43legacy_rfkill
*rfk
= container_of(work
,
33 struct b43legacy_rfkill
,
35 struct b43legacy_wl
*wl
= container_of(rfk
, struct b43legacy_wl
,
37 struct b43legacy_wldev
*dev
;
38 enum rfkill_state state
;
40 mutex_lock(&wl
->mutex
);
41 dev
= wl
->current_dev
;
42 if (b43legacy_status(dev
) < B43legacy_STAT_INITIALIZED
) {
43 mutex_unlock(&wl
->mutex
);
46 if (dev
->radio_hw_enable
)
47 state
= RFKILL_STATE_ON
;
49 state
= RFKILL_STATE_OFF
;
50 b43legacyinfo(wl
, "Radio hardware status changed to %s\n",
51 dev
->radio_hw_enable
? "ENABLED" : "DISABLED");
52 mutex_unlock(&wl
->mutex
);
55 /* Be careful. This calls back into the software toggle
56 * routines. So we must unlock before calling. */
57 rfkill_switch_all(rfk
->rfkill
->type
, state
);
61 /* Called when the RFKILL toggled in hardware.
62 * This is called with the mutex locked. */
63 void b43legacy_rfkill_toggled(struct b43legacy_wldev
*dev
, bool on
)
65 struct b43legacy_wl
*wl
= dev
->wl
;
67 B43legacy_WARN_ON(b43legacy_status(dev
) < B43legacy_STAT_INITIALIZED
);
68 /* Update the RF status asynchronously, as rfkill will
69 * call back into the software toggle handler.
70 * This would deadlock if done synchronously. */
71 queue_work(wl
->hw
->workqueue
, &wl
->rfkill
.notify_work
);
74 /* Called when the RFKILL toggled in software.
75 * This is called without locking. */
76 static int b43legacy_rfkill_soft_toggle(void *data
, enum rfkill_state state
)
78 struct b43legacy_wldev
*dev
= data
;
79 struct b43legacy_wl
*wl
= dev
->wl
;
82 mutex_lock(&wl
->mutex
);
83 if (b43legacy_status(dev
) < B43legacy_STAT_INITIALIZED
)
88 if (!dev
->radio_hw_enable
) {
89 /* No luck. We can't toggle the hardware RF-kill
90 * button from software. */
94 if (!dev
->phy
.radio_on
)
95 b43legacy_radio_turn_on(dev
);
97 case RFKILL_STATE_OFF
:
98 if (dev
->phy
.radio_on
)
99 b43legacy_radio_turn_off(dev
, 0);
104 mutex_unlock(&wl
->mutex
);
109 char *b43legacy_rfkill_led_name(struct b43legacy_wldev
*dev
)
111 struct b43legacy_wl
*wl
= dev
->wl
;
113 if (!wl
->rfkill
.rfkill
)
115 return rfkill_get_led_name(wl
->rfkill
.rfkill
);
118 void b43legacy_rfkill_init(struct b43legacy_wldev
*dev
)
120 struct b43legacy_wl
*wl
= dev
->wl
;
121 struct b43legacy_rfkill
*rfk
= &(wl
->rfkill
);
124 snprintf(rfk
->name
, sizeof(rfk
->name
),
125 "b43legacy-%s", wiphy_name(wl
->hw
->wiphy
));
126 rfk
->rfkill
= rfkill_allocate(dev
->dev
->dev
, RFKILL_TYPE_WLAN
);
129 rfk
->rfkill
->name
= rfk
->name
;
130 rfk
->rfkill
->state
= RFKILL_STATE_ON
;
131 rfk
->rfkill
->data
= dev
;
132 rfk
->rfkill
->toggle_radio
= b43legacy_rfkill_soft_toggle
;
133 rfk
->rfkill
->user_claim_unsupported
= 1;
135 INIT_WORK(&rfk
->notify_work
, b43legacy_notify_rfkill_press
);
137 err
= rfkill_register(rfk
->rfkill
);
143 b43legacywarn(dev
->wl
, "Failed to initialize the RF-kill button\n");
144 rfkill_free(rfk
->rfkill
);
148 void b43legacy_rfkill_exit(struct b43legacy_wldev
*dev
)
150 struct b43legacy_rfkill
*rfk
= &(dev
->wl
->rfkill
);
154 cancel_work_sync(&rfk
->notify_work
);
155 rfkill_unregister(rfk
->rfkill
);
156 rfkill_free(rfk
->rfkill
);