blob: fdf87d2ab25e358ddf8e5d9aec29e5392a2cf432 [file] [log] [blame]
Ivo van Doorncf4328c2007-05-07 00:34:20 -07001/*
Ivo van Doornfe242cf2007-09-27 14:57:05 -07002 * Copyright (C) 2006 - 2007 Ivo van Doorn
Ivo van Doorncf4328c2007-05-07 00:34:20 -07003 * Copyright (C) 2007 Dmitry Torokhov
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the
17 * Free Software Foundation, Inc.,
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/init.h>
24#include <linux/workqueue.h>
25#include <linux/capability.h>
26#include <linux/list.h>
27#include <linux/mutex.h>
28#include <linux/rfkill.h>
29
Michael Buesch27366222007-11-02 20:18:11 +010030/* Get declaration of rfkill_switch_all() to shut up sparse. */
31#include "rfkill-input.h"
32
33
Ivo van Doorncf4328c2007-05-07 00:34:20 -070034MODULE_AUTHOR("Ivo van Doorn <IvDoorn@gmail.com>");
35MODULE_VERSION("1.0");
36MODULE_DESCRIPTION("RF switch support");
37MODULE_LICENSE("GPL");
38
39static LIST_HEAD(rfkill_list); /* list of registered rf switches */
Henrique de Moraes Holschuh15635742008-08-26 11:58:00 -030040static DEFINE_MUTEX(rfkill_global_mutex);
Ivo van Doorncf4328c2007-05-07 00:34:20 -070041
Henrique de Moraes Holschuh5005657c2008-06-23 17:46:42 -030042static unsigned int rfkill_default_state = RFKILL_STATE_UNBLOCKED;
Henrique de Moraes Holschuhe954b0b2008-06-23 17:22:59 -030043module_param_named(default_state, rfkill_default_state, uint, 0444);
44MODULE_PARM_DESC(default_state,
45 "Default initial state for all radio types, 0 = radio off");
46
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -030047struct rfkill_gsw_state {
48 enum rfkill_state current_state;
49 enum rfkill_state default_state;
50};
51
52static struct rfkill_gsw_state rfkill_global_states[RFKILL_TYPE_MAX];
53static unsigned long rfkill_states_lockdflt[BITS_TO_LONGS(RFKILL_TYPE_MAX)];
Ivo van Doorncf4328c2007-05-07 00:34:20 -070054
Henrique de Moraes Holschuh79399a82008-06-23 17:23:03 -030055static BLOCKING_NOTIFIER_HEAD(rfkill_notifier_list);
56
57
58/**
59 * register_rfkill_notifier - Add notifier to rfkill notifier chain
60 * @nb: pointer to the new entry to add to the chain
61 *
62 * See blocking_notifier_chain_register() for return value and further
63 * observations.
64 *
65 * Adds a notifier to the rfkill notifier chain. The chain will be
66 * called with a pointer to the relevant rfkill structure as a parameter,
67 * refer to include/linux/rfkill.h for the possible events.
68 *
69 * Notifiers added to this chain are to always return NOTIFY_DONE. This
70 * chain is a blocking notifier chain: notifiers can sleep.
71 *
72 * Calls to this chain may have been done through a workqueue. One must
73 * assume unordered asynchronous behaviour, there is no way to know if
74 * actions related to the event that generated the notification have been
75 * carried out already.
76 */
77int register_rfkill_notifier(struct notifier_block *nb)
78{
Henrique de Moraes Holschuhf745ba02008-08-26 11:57:59 -030079 BUG_ON(!nb);
Henrique de Moraes Holschuh79399a82008-06-23 17:23:03 -030080 return blocking_notifier_chain_register(&rfkill_notifier_list, nb);
81}
82EXPORT_SYMBOL_GPL(register_rfkill_notifier);
83
84/**
85 * unregister_rfkill_notifier - remove notifier from rfkill notifier chain
86 * @nb: pointer to the entry to remove from the chain
87 *
88 * See blocking_notifier_chain_unregister() for return value and further
89 * observations.
90 *
91 * Removes a notifier from the rfkill notifier chain.
92 */
93int unregister_rfkill_notifier(struct notifier_block *nb)
94{
Henrique de Moraes Holschuhf745ba02008-08-26 11:57:59 -030095 BUG_ON(!nb);
Henrique de Moraes Holschuh79399a82008-06-23 17:23:03 -030096 return blocking_notifier_chain_unregister(&rfkill_notifier_list, nb);
97}
98EXPORT_SYMBOL_GPL(unregister_rfkill_notifier);
99
Michael Buesch135900c2007-09-27 21:33:12 +0200100
101static void rfkill_led_trigger(struct rfkill *rfkill,
102 enum rfkill_state state)
103{
104#ifdef CONFIG_RFKILL_LEDS
105 struct led_trigger *led = &rfkill->led_trigger;
106
107 if (!led->name)
108 return;
Henrique de Moraes Holschuh5005657c2008-06-23 17:46:42 -0300109 if (state != RFKILL_STATE_UNBLOCKED)
Michael Buesch135900c2007-09-27 21:33:12 +0200110 led_trigger_event(led, LED_OFF);
111 else
112 led_trigger_event(led, LED_FULL);
113#endif /* CONFIG_RFKILL_LEDS */
114}
115
Dmitry Baryshkov96185662008-07-22 14:21:59 +0400116#ifdef CONFIG_RFKILL_LEDS
117static void rfkill_led_trigger_activate(struct led_classdev *led)
118{
119 struct rfkill *rfkill = container_of(led->trigger,
120 struct rfkill, led_trigger);
121
122 rfkill_led_trigger(rfkill, rfkill->state);
123}
124#endif /* CONFIG_RFKILL_LEDS */
125
Henrique de Moraes Holschuh79399a82008-06-23 17:23:03 -0300126static void notify_rfkill_state_change(struct rfkill *rfkill)
127{
Henrique de Moraes Holschuh417bd252008-10-03 16:58:05 -0300128 rfkill_led_trigger(rfkill, rfkill->state);
Henrique de Moraes Holschuh79399a82008-06-23 17:23:03 -0300129 blocking_notifier_call_chain(&rfkill_notifier_list,
130 RFKILL_STATE_CHANGED,
131 rfkill);
132}
133
Henrique de Moraes Holschuh801e49a2008-06-23 17:23:00 -0300134static void update_rfkill_state(struct rfkill *rfkill)
135{
Henrique de Moraes Holschuh79399a82008-06-23 17:23:03 -0300136 enum rfkill_state newstate, oldstate;
Henrique de Moraes Holschuh801e49a2008-06-23 17:23:00 -0300137
138 if (rfkill->get_state) {
139 mutex_lock(&rfkill->mutex);
Henrique de Moraes Holschuh79399a82008-06-23 17:23:03 -0300140 if (!rfkill->get_state(rfkill->data, &newstate)) {
141 oldstate = rfkill->state;
Henrique de Moraes Holschuh801e49a2008-06-23 17:23:00 -0300142 rfkill->state = newstate;
Henrique de Moraes Holschuh79399a82008-06-23 17:23:03 -0300143 if (oldstate != newstate)
144 notify_rfkill_state_change(rfkill);
145 }
Henrique de Moraes Holschuh801e49a2008-06-23 17:23:00 -0300146 mutex_unlock(&rfkill->mutex);
147 }
148}
149
Henrique de Moraes Holschuh5005657c2008-06-23 17:46:42 -0300150/**
151 * rfkill_toggle_radio - wrapper for toggle_radio hook
Henrique de Moraes Holschuh5005657c2008-06-23 17:46:42 -0300152 * @rfkill: the rfkill struct to use
153 * @force: calls toggle_radio even if cache says it is not needed,
154 * and also makes sure notifications of the state will be
155 * sent even if it didn't change
156 * @state: the new state to call toggle_radio() with
157 *
Henrique de Moraes Holschuh0f687e92008-07-03 13:14:56 -0300158 * Calls rfkill->toggle_radio, enforcing the API for toggle_radio
159 * calls and handling all the red tape such as issuing notifications
160 * if the call is successful.
161 *
Henrique de Moraes Holschuhe10e0df2008-08-02 14:56:25 -0300162 * Suspended devices are not touched at all, and -EAGAIN is returned.
163 *
Henrique de Moraes Holschuh435307a2008-07-21 21:18:22 -0300164 * Note that the @force parameter cannot override a (possibly cached)
165 * state of RFKILL_STATE_HARD_BLOCKED. Any device making use of
Henrique de Moraes Holschuh5005657c2008-06-23 17:46:42 -0300166 * RFKILL_STATE_HARD_BLOCKED implements either get_state() or
167 * rfkill_force_state(), so the cache either is bypassed or valid.
168 *
169 * Note that we do call toggle_radio for RFKILL_STATE_SOFT_BLOCKED
170 * even if the radio is in RFKILL_STATE_HARD_BLOCKED state, so as to
171 * give the driver a hint that it should double-BLOCK the transmitter.
172 *
Henrique de Moraes Holschuh064af112008-07-21 21:18:20 -0300173 * Caller must have acquired rfkill->mutex.
Henrique de Moraes Holschuh5005657c2008-06-23 17:46:42 -0300174 */
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700175static int rfkill_toggle_radio(struct rfkill *rfkill,
Henrique de Moraes Holschuh526324b2008-06-23 17:23:02 -0300176 enum rfkill_state state,
177 int force)
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700178{
Michael Buesch7f4c5342007-11-28 17:49:34 +0100179 int retval = 0;
Henrique de Moraes Holschuh801e49a2008-06-23 17:23:00 -0300180 enum rfkill_state oldstate, newstate;
181
Henrique de Moraes Holschuhe10e0df2008-08-02 14:56:25 -0300182 if (unlikely(rfkill->dev.power.power_state.event & PM_EVENT_SLEEP))
183 return -EBUSY;
184
Henrique de Moraes Holschuh801e49a2008-06-23 17:23:00 -0300185 oldstate = rfkill->state;
186
Henrique de Moraes Holschuh526324b2008-06-23 17:23:02 -0300187 if (rfkill->get_state && !force &&
Henrique de Moraes Holschuh801e49a2008-06-23 17:23:00 -0300188 !rfkill->get_state(rfkill->data, &newstate))
189 rfkill->state = newstate;
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700190
Henrique de Moraes Holschuh5005657c2008-06-23 17:46:42 -0300191 switch (state) {
192 case RFKILL_STATE_HARD_BLOCKED:
193 /* typically happens when refreshing hardware state,
194 * such as on resume */
195 state = RFKILL_STATE_SOFT_BLOCKED;
196 break;
197 case RFKILL_STATE_UNBLOCKED:
198 /* force can't override this, only rfkill_force_state() can */
199 if (rfkill->state == RFKILL_STATE_HARD_BLOCKED)
200 return -EPERM;
201 break;
202 case RFKILL_STATE_SOFT_BLOCKED:
203 /* nothing to do, we want to give drivers the hint to double
204 * BLOCK even a transmitter that is already in state
205 * RFKILL_STATE_HARD_BLOCKED */
206 break;
Henrique de Moraes Holschuh96c87602008-08-02 15:11:00 -0300207 default:
Henrique de Moraes Holschuhf745ba02008-08-26 11:57:59 -0300208 WARN(1, KERN_WARNING
209 "rfkill: illegal state %d passed as parameter "
210 "to rfkill_toggle_radio\n", state);
Henrique de Moraes Holschuh96c87602008-08-02 15:11:00 -0300211 return -EINVAL;
Henrique de Moraes Holschuh5005657c2008-06-23 17:46:42 -0300212 }
213
Henrique de Moraes Holschuh526324b2008-06-23 17:23:02 -0300214 if (force || state != rfkill->state) {
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700215 retval = rfkill->toggle_radio(rfkill->data, state);
Henrique de Moraes Holschuh5005657c2008-06-23 17:46:42 -0300216 /* never allow a HARD->SOFT downgrade! */
217 if (!retval && rfkill->state != RFKILL_STATE_HARD_BLOCKED)
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700218 rfkill->state = state;
219 }
220
Henrique de Moraes Holschuh417bd252008-10-03 16:58:05 -0300221 if (force || rfkill->state != oldstate)
Henrique de Moraes Holschuh79399a82008-06-23 17:23:03 -0300222 notify_rfkill_state_change(rfkill);
Henrique de Moraes Holschuh801e49a2008-06-23 17:23:00 -0300223
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700224 return retval;
225}
226
227/**
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300228 * __rfkill_switch_all - Toggle state of all switches of given type
Henrique de Moraes Holschuh435307a2008-07-21 21:18:22 -0300229 * @type: type of interfaces to be affected
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700230 * @state: the new state
231 *
Henrique de Moraes Holschuh435307a2008-07-21 21:18:22 -0300232 * This function toggles the state of all switches of given type,
233 * unless a specific switch is claimed by userspace (in which case,
Henrique de Moraes Holschuhe10e0df2008-08-02 14:56:25 -0300234 * that switch is left alone) or suspended.
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300235 *
Henrique de Moraes Holschuh15635742008-08-26 11:58:00 -0300236 * Caller must have acquired rfkill_global_mutex.
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700237 */
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300238static void __rfkill_switch_all(const enum rfkill_type type,
239 const enum rfkill_state state)
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700240{
241 struct rfkill *rfkill;
242
Henrique de Moraes Holschuhf745ba02008-08-26 11:57:59 -0300243 if (WARN((state >= RFKILL_STATE_MAX || type >= RFKILL_TYPE_MAX),
244 KERN_WARNING
245 "rfkill: illegal state %d or type %d "
246 "passed as parameter to __rfkill_switch_all\n",
247 state, type))
Henrique de Moraes Holschuh96c87602008-08-02 15:11:00 -0300248 return;
249
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300250 rfkill_global_states[type].current_state = state;
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700251 list_for_each_entry(rfkill, &rfkill_list, node) {
Henrique de Moraes Holschuh064af112008-07-21 21:18:20 -0300252 if ((!rfkill->user_claim) && (rfkill->type == type)) {
253 mutex_lock(&rfkill->mutex);
Henrique de Moraes Holschuh526324b2008-06-23 17:23:02 -0300254 rfkill_toggle_radio(rfkill, state, 0);
Henrique de Moraes Holschuh064af112008-07-21 21:18:20 -0300255 mutex_unlock(&rfkill->mutex);
256 }
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700257 }
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300258}
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700259
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300260/**
261 * rfkill_switch_all - Toggle state of all switches of given type
262 * @type: type of interfaces to be affected
263 * @state: the new state
264 *
Henrique de Moraes Holschuh15635742008-08-26 11:58:00 -0300265 * Acquires rfkill_global_mutex and calls __rfkill_switch_all(@type, @state).
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300266 * Please refer to __rfkill_switch_all() for details.
267 */
268void rfkill_switch_all(enum rfkill_type type, enum rfkill_state state)
269{
Henrique de Moraes Holschuh15635742008-08-26 11:58:00 -0300270 mutex_lock(&rfkill_global_mutex);
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300271 __rfkill_switch_all(type, state);
Henrique de Moraes Holschuh15635742008-08-26 11:58:00 -0300272 mutex_unlock(&rfkill_global_mutex);
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700273}
274EXPORT_SYMBOL(rfkill_switch_all);
275
Henrique de Moraes Holschuh801e49a2008-06-23 17:23:00 -0300276/**
Henrique de Moraes Holschuh4081f002008-06-23 17:23:07 -0300277 * rfkill_epo - emergency power off all transmitters
278 *
Henrique de Moraes Holschuhe10e0df2008-08-02 14:56:25 -0300279 * This kicks all non-suspended rfkill devices to RFKILL_STATE_SOFT_BLOCKED,
Henrique de Moraes Holschuh15635742008-08-26 11:58:00 -0300280 * ignoring everything in its path but rfkill_global_mutex and rfkill->mutex.
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300281 *
282 * The global state before the EPO is saved and can be restored later
283 * using rfkill_restore_states().
Henrique de Moraes Holschuh4081f002008-06-23 17:23:07 -0300284 */
285void rfkill_epo(void)
286{
287 struct rfkill *rfkill;
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300288 int i;
Henrique de Moraes Holschuh4081f002008-06-23 17:23:07 -0300289
Henrique de Moraes Holschuh15635742008-08-26 11:58:00 -0300290 mutex_lock(&rfkill_global_mutex);
291
Henrique de Moraes Holschuh4081f002008-06-23 17:23:07 -0300292 list_for_each_entry(rfkill, &rfkill_list, node) {
Henrique de Moraes Holschuh064af112008-07-21 21:18:20 -0300293 mutex_lock(&rfkill->mutex);
Henrique de Moraes Holschuh5005657c2008-06-23 17:46:42 -0300294 rfkill_toggle_radio(rfkill, RFKILL_STATE_SOFT_BLOCKED, 1);
Henrique de Moraes Holschuh064af112008-07-21 21:18:20 -0300295 mutex_unlock(&rfkill->mutex);
Henrique de Moraes Holschuh4081f002008-06-23 17:23:07 -0300296 }
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300297 for (i = 0; i < RFKILL_TYPE_MAX; i++) {
298 rfkill_global_states[i].default_state =
299 rfkill_global_states[i].current_state;
300 rfkill_global_states[i].current_state =
301 RFKILL_STATE_SOFT_BLOCKED;
302 }
Henrique de Moraes Holschuh15635742008-08-26 11:58:00 -0300303 mutex_unlock(&rfkill_global_mutex);
Henrique de Moraes Holschuh4081f002008-06-23 17:23:07 -0300304}
305EXPORT_SYMBOL_GPL(rfkill_epo);
306
307/**
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300308 * rfkill_restore_states - restore global states
309 *
310 * Restore (and sync switches to) the global state from the
311 * states in rfkill_default_states. This can undo the effects of
312 * a call to rfkill_epo().
313 */
314void rfkill_restore_states(void)
315{
316 int i;
317
Henrique de Moraes Holschuh15635742008-08-26 11:58:00 -0300318 mutex_lock(&rfkill_global_mutex);
319
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300320 for (i = 0; i < RFKILL_TYPE_MAX; i++)
321 __rfkill_switch_all(i, rfkill_global_states[i].default_state);
Henrique de Moraes Holschuh15635742008-08-26 11:58:00 -0300322 mutex_unlock(&rfkill_global_mutex);
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300323}
324EXPORT_SYMBOL_GPL(rfkill_restore_states);
325
326/**
Henrique de Moraes Holschuh68d24132008-10-09 18:15:30 -0300327 * rfkill_get_global_state - returns global state for a type
328 * @type: the type to get the global state of
329 *
330 * Returns the current global state for a given wireless
331 * device type.
332 */
333enum rfkill_state rfkill_get_global_state(const enum rfkill_type type)
334{
335 return rfkill_global_states[type].current_state;
336}
337EXPORT_SYMBOL_GPL(rfkill_get_global_state);
338
339/**
Henrique de Moraes Holschuh801e49a2008-06-23 17:23:00 -0300340 * rfkill_force_state - Force the internal rfkill radio state
341 * @rfkill: pointer to the rfkill class to modify.
342 * @state: the current radio state the class should be forced to.
343 *
344 * This function updates the internal state of the radio cached
345 * by the rfkill class. It should be used when the driver gets
346 * a notification by the firmware/hardware of the current *real*
347 * state of the radio rfkill switch.
348 *
Henrique de Moraes Holschuh2fd9b222008-07-21 21:18:17 -0300349 * Devices which are subject to external changes on their rfkill
350 * state (such as those caused by a hardware rfkill line) MUST
351 * have their driver arrange to call rfkill_force_state() as soon
352 * as possible after such a change.
353 *
354 * This function may not be called from an atomic context.
Henrique de Moraes Holschuh801e49a2008-06-23 17:23:00 -0300355 */
356int rfkill_force_state(struct rfkill *rfkill, enum rfkill_state state)
357{
Henrique de Moraes Holschuh79399a82008-06-23 17:23:03 -0300358 enum rfkill_state oldstate;
359
Henrique de Moraes Holschuhf745ba02008-08-26 11:57:59 -0300360 BUG_ON(!rfkill);
361 if (WARN((state >= RFKILL_STATE_MAX),
362 KERN_WARNING
363 "rfkill: illegal state %d passed as parameter "
364 "to rfkill_force_state\n", state))
Henrique de Moraes Holschuh801e49a2008-06-23 17:23:00 -0300365 return -EINVAL;
366
367 mutex_lock(&rfkill->mutex);
Henrique de Moraes Holschuh79399a82008-06-23 17:23:03 -0300368
369 oldstate = rfkill->state;
Henrique de Moraes Holschuh801e49a2008-06-23 17:23:00 -0300370 rfkill->state = state;
Henrique de Moraes Holschuh79399a82008-06-23 17:23:03 -0300371
372 if (state != oldstate)
373 notify_rfkill_state_change(rfkill);
374
Henrique de Moraes Holschuh801e49a2008-06-23 17:23:00 -0300375 mutex_unlock(&rfkill->mutex);
376
377 return 0;
378}
379EXPORT_SYMBOL(rfkill_force_state);
380
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700381static ssize_t rfkill_name_show(struct device *dev,
382 struct device_attribute *attr,
383 char *buf)
384{
385 struct rfkill *rfkill = to_rfkill(dev);
386
387 return sprintf(buf, "%s\n", rfkill->name);
388}
389
Henrique de Moraes Holschuh99c632e2008-06-23 17:23:04 -0300390static const char *rfkill_get_type_str(enum rfkill_type type)
391{
392 switch (type) {
393 case RFKILL_TYPE_WLAN:
394 return "wlan";
395 case RFKILL_TYPE_BLUETOOTH:
396 return "bluetooth";
397 case RFKILL_TYPE_UWB:
398 return "ultrawideband";
399 case RFKILL_TYPE_WIMAX:
400 return "wimax";
401 case RFKILL_TYPE_WWAN:
402 return "wwan";
403 default:
404 BUG();
405 }
406}
407
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700408static ssize_t rfkill_type_show(struct device *dev,
409 struct device_attribute *attr,
410 char *buf)
411{
412 struct rfkill *rfkill = to_rfkill(dev);
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700413
Henrique de Moraes Holschuh99c632e2008-06-23 17:23:04 -0300414 return sprintf(buf, "%s\n", rfkill_get_type_str(rfkill->type));
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700415}
416
417static ssize_t rfkill_state_show(struct device *dev,
418 struct device_attribute *attr,
419 char *buf)
420{
421 struct rfkill *rfkill = to_rfkill(dev);
422
Henrique de Moraes Holschuh801e49a2008-06-23 17:23:00 -0300423 update_rfkill_state(rfkill);
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700424 return sprintf(buf, "%d\n", rfkill->state);
425}
426
427static ssize_t rfkill_state_store(struct device *dev,
428 struct device_attribute *attr,
429 const char *buf, size_t count)
430{
431 struct rfkill *rfkill = to_rfkill(dev);
Henrique de Moraes Holschuh849e0572008-08-26 11:57:57 -0300432 unsigned long state;
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700433 int error;
434
435 if (!capable(CAP_NET_ADMIN))
436 return -EPERM;
437
Henrique de Moraes Holschuh849e0572008-08-26 11:57:57 -0300438 error = strict_strtoul(buf, 0, &state);
439 if (error)
440 return error;
441
Henrique de Moraes Holschuh5005657c2008-06-23 17:46:42 -0300442 /* RFKILL_STATE_HARD_BLOCKED is illegal here... */
443 if (state != RFKILL_STATE_UNBLOCKED &&
444 state != RFKILL_STATE_SOFT_BLOCKED)
445 return -EINVAL;
446
Henrique de Moraes Holschuhcf4b4aa2008-10-09 18:15:29 -0300447 error = mutex_lock_killable(&rfkill->mutex);
448 if (error)
449 return error;
Henrique de Moraes Holschuh5005657c2008-06-23 17:46:42 -0300450 error = rfkill_toggle_radio(rfkill, state, 0);
Michael Buesch7f4c5342007-11-28 17:49:34 +0100451 mutex_unlock(&rfkill->mutex);
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700452
Michael Buesch7f4c5342007-11-28 17:49:34 +0100453 return error ? error : count;
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700454}
455
456static ssize_t rfkill_claim_show(struct device *dev,
457 struct device_attribute *attr,
458 char *buf)
459{
460 struct rfkill *rfkill = to_rfkill(dev);
461
Felipe Balbi01b510b2008-08-26 11:57:58 -0300462 return sprintf(buf, "%d\n", rfkill->user_claim);
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700463}
464
465static ssize_t rfkill_claim_store(struct device *dev,
466 struct device_attribute *attr,
467 const char *buf, size_t count)
468{
469 struct rfkill *rfkill = to_rfkill(dev);
Henrique de Moraes Holschuh849e0572008-08-26 11:57:57 -0300470 unsigned long claim_tmp;
471 bool claim;
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700472 int error;
473
474 if (!capable(CAP_NET_ADMIN))
475 return -EPERM;
476
Henrique de Moraes Holschuh064af112008-07-21 21:18:20 -0300477 if (rfkill->user_claim_unsupported)
478 return -EOPNOTSUPP;
479
Henrique de Moraes Holschuh849e0572008-08-26 11:57:57 -0300480 error = strict_strtoul(buf, 0, &claim_tmp);
481 if (error)
482 return error;
483 claim = !!claim_tmp;
484
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700485 /*
486 * Take the global lock to make sure the kernel is not in
487 * the middle of rfkill_switch_all
488 */
Henrique de Moraes Holschuhcf4b4aa2008-10-09 18:15:29 -0300489 error = mutex_lock_killable(&rfkill_global_mutex);
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700490 if (error)
491 return error;
492
493 if (rfkill->user_claim != claim) {
Henrique de Moraes Holschuh064af112008-07-21 21:18:20 -0300494 if (!claim) {
495 mutex_lock(&rfkill->mutex);
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700496 rfkill_toggle_radio(rfkill,
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300497 rfkill_global_states[rfkill->type].current_state,
498 0);
Henrique de Moraes Holschuh064af112008-07-21 21:18:20 -0300499 mutex_unlock(&rfkill->mutex);
500 }
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700501 rfkill->user_claim = claim;
502 }
503
Henrique de Moraes Holschuh15635742008-08-26 11:58:00 -0300504 mutex_unlock(&rfkill_global_mutex);
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700505
Michael Buesch20405c02007-09-27 21:34:23 +0200506 return error ? error : count;
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700507}
508
509static struct device_attribute rfkill_dev_attrs[] = {
510 __ATTR(name, S_IRUGO, rfkill_name_show, NULL),
511 __ATTR(type, S_IRUGO, rfkill_type_show, NULL),
Ivo van Doornc81de6a2007-07-18 15:38:03 -0700512 __ATTR(state, S_IRUGO|S_IWUSR, rfkill_state_show, rfkill_state_store),
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700513 __ATTR(claim, S_IRUGO|S_IWUSR, rfkill_claim_show, rfkill_claim_store),
514 __ATTR_NULL
515};
516
517static void rfkill_release(struct device *dev)
518{
519 struct rfkill *rfkill = to_rfkill(dev);
520
521 kfree(rfkill);
522 module_put(THIS_MODULE);
523}
524
525#ifdef CONFIG_PM
526static int rfkill_suspend(struct device *dev, pm_message_t state)
527{
Henrique de Moraes Holschuhbed7aac2008-08-26 11:58:01 -0300528 /* mark class device as suspended */
529 if (dev->power.power_state.event != state.event)
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700530 dev->power.power_state = state;
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700531
532 return 0;
533}
534
535static int rfkill_resume(struct device *dev)
536{
537 struct rfkill *rfkill = to_rfkill(dev);
538
539 if (dev->power.power_state.event != PM_EVENT_ON) {
540 mutex_lock(&rfkill->mutex);
541
Henrique de Moraes Holschuhe10e0df2008-08-02 14:56:25 -0300542 dev->power.power_state.event = PM_EVENT_ON;
543
Henrique de Moraes Holschuh526324b2008-06-23 17:23:02 -0300544 /* restore radio state AND notify everybody */
545 rfkill_toggle_radio(rfkill, rfkill->state, 1);
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700546
547 mutex_unlock(&rfkill->mutex);
548 }
549
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700550 return 0;
551}
552#else
553#define rfkill_suspend NULL
554#define rfkill_resume NULL
555#endif
556
Henrique de Moraes Holschuhffb67c32008-06-23 17:23:05 -0300557static int rfkill_blocking_uevent_notifier(struct notifier_block *nb,
558 unsigned long eventid,
559 void *data)
560{
561 struct rfkill *rfkill = (struct rfkill *)data;
562
563 switch (eventid) {
564 case RFKILL_STATE_CHANGED:
565 kobject_uevent(&rfkill->dev.kobj, KOBJ_CHANGE);
566 break;
567 default:
568 break;
569 }
570
571 return NOTIFY_DONE;
572}
573
574static struct notifier_block rfkill_blocking_uevent_nb = {
575 .notifier_call = rfkill_blocking_uevent_notifier,
576 .priority = 0,
577};
578
579static int rfkill_dev_uevent(struct device *dev, struct kobj_uevent_env *env)
580{
581 struct rfkill *rfkill = to_rfkill(dev);
582 int error;
583
584 error = add_uevent_var(env, "RFKILL_NAME=%s", rfkill->name);
585 if (error)
586 return error;
587 error = add_uevent_var(env, "RFKILL_TYPE=%s",
588 rfkill_get_type_str(rfkill->type));
589 if (error)
590 return error;
591 error = add_uevent_var(env, "RFKILL_STATE=%d", rfkill->state);
592 return error;
593}
594
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700595static struct class rfkill_class = {
596 .name = "rfkill",
597 .dev_release = rfkill_release,
598 .dev_attrs = rfkill_dev_attrs,
599 .suspend = rfkill_suspend,
600 .resume = rfkill_resume,
Henrique de Moraes Holschuhffb67c32008-06-23 17:23:05 -0300601 .dev_uevent = rfkill_dev_uevent,
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700602};
603
Henrique de Moraes Holschuh02589f62008-08-02 15:10:57 -0300604static int rfkill_check_duplicity(const struct rfkill *rfkill)
605{
606 struct rfkill *p;
607 unsigned long seen[BITS_TO_LONGS(RFKILL_TYPE_MAX)];
608
609 memset(seen, 0, sizeof(seen));
610
611 list_for_each_entry(p, &rfkill_list, node) {
Henrique de Moraes Holschuhf745ba02008-08-26 11:57:59 -0300612 if (WARN((p == rfkill), KERN_WARNING
613 "rfkill: illegal attempt to register "
614 "an already registered rfkill struct\n"))
Henrique de Moraes Holschuh02589f62008-08-02 15:10:57 -0300615 return -EEXIST;
Henrique de Moraes Holschuh02589f62008-08-02 15:10:57 -0300616 set_bit(p->type, seen);
617 }
618
619 /* 0: first switch of its kind */
620 return test_bit(rfkill->type, seen);
621}
622
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700623static int rfkill_add_switch(struct rfkill *rfkill)
624{
Henrique de Moraes Holschuh02589f62008-08-02 15:10:57 -0300625 int error;
626
Henrique de Moraes Holschuh15635742008-08-26 11:58:00 -0300627 mutex_lock(&rfkill_global_mutex);
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700628
Henrique de Moraes Holschuh02589f62008-08-02 15:10:57 -0300629 error = rfkill_check_duplicity(rfkill);
630 if (error < 0)
631 goto unlock_out;
632
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300633 if (!error) {
634 /* lock default after first use */
635 set_bit(rfkill->type, rfkill_states_lockdflt);
636 rfkill_global_states[rfkill->type].current_state =
637 rfkill_global_states[rfkill->type].default_state;
638 }
639
640 rfkill_toggle_radio(rfkill,
641 rfkill_global_states[rfkill->type].current_state,
642 0);
Henrique de Moraes Holschuhfd4484a2008-07-03 13:14:57 -0300643
644 list_add_tail(&rfkill->node, &rfkill_list);
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700645
Henrique de Moraes Holschuh02589f62008-08-02 15:10:57 -0300646 error = 0;
647unlock_out:
Henrique de Moraes Holschuh15635742008-08-26 11:58:00 -0300648 mutex_unlock(&rfkill_global_mutex);
Michael Buesch7319f1e2007-10-28 15:16:50 +0100649
Henrique de Moraes Holschuh02589f62008-08-02 15:10:57 -0300650 return error;
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700651}
652
653static void rfkill_remove_switch(struct rfkill *rfkill)
654{
Henrique de Moraes Holschuh15635742008-08-26 11:58:00 -0300655 mutex_lock(&rfkill_global_mutex);
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700656 list_del_init(&rfkill->node);
Henrique de Moraes Holschuh15635742008-08-26 11:58:00 -0300657 mutex_unlock(&rfkill_global_mutex);
Henrique de Moraes Holschuh064af112008-07-21 21:18:20 -0300658
659 mutex_lock(&rfkill->mutex);
660 rfkill_toggle_radio(rfkill, RFKILL_STATE_SOFT_BLOCKED, 1);
661 mutex_unlock(&rfkill->mutex);
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700662}
663
664/**
665 * rfkill_allocate - allocate memory for rfkill structure.
666 * @parent: device that has rf switch on it
Ivo van Doorn234a0ca2007-09-13 09:20:42 +0200667 * @type: type of the switch (RFKILL_TYPE_*)
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700668 *
669 * This function should be called by the network driver when it needs
Henrique de Moraes Holschuh435307a2008-07-21 21:18:22 -0300670 * rfkill structure. Once the structure is allocated the driver should
671 * finish its initialization by setting the name, private data, enable_radio
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700672 * and disable_radio methods and then register it with rfkill_register().
Henrique de Moraes Holschuh435307a2008-07-21 21:18:22 -0300673 *
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700674 * NOTE: If registration fails the structure shoudl be freed by calling
675 * rfkill_free() otherwise rfkill_unregister() should be used.
676 */
Henrique de Moraes Holschuh77fba132008-08-02 15:10:59 -0300677struct rfkill * __must_check rfkill_allocate(struct device *parent,
678 enum rfkill_type type)
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700679{
680 struct rfkill *rfkill;
681 struct device *dev;
682
Henrique de Moraes Holschuhf745ba02008-08-26 11:57:59 -0300683 if (WARN((type >= RFKILL_TYPE_MAX),
684 KERN_WARNING
685 "rfkill: illegal type %d passed as parameter "
686 "to rfkill_allocate\n", type))
687 return NULL;
688
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700689 rfkill = kzalloc(sizeof(struct rfkill), GFP_KERNEL);
Ivo van Doornd007da12007-05-19 12:24:39 -0700690 if (!rfkill)
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700691 return NULL;
692
693 mutex_init(&rfkill->mutex);
694 INIT_LIST_HEAD(&rfkill->node);
695 rfkill->type = type;
696
697 dev = &rfkill->dev;
698 dev->class = &rfkill_class;
699 dev->parent = parent;
700 device_initialize(dev);
701
702 __module_get(THIS_MODULE);
703
704 return rfkill;
705}
706EXPORT_SYMBOL(rfkill_allocate);
707
708/**
709 * rfkill_free - Mark rfkill structure for deletion
710 * @rfkill: rfkill structure to be destroyed
711 *
Henrique de Moraes Holschuh435307a2008-07-21 21:18:22 -0300712 * Decrements reference count of the rfkill structure so it is destroyed.
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700713 * Note that rfkill_free() should _not_ be called after rfkill_unregister().
714 */
715void rfkill_free(struct rfkill *rfkill)
716{
717 if (rfkill)
718 put_device(&rfkill->dev);
719}
720EXPORT_SYMBOL(rfkill_free);
721
Michael Buesch135900c2007-09-27 21:33:12 +0200722static void rfkill_led_trigger_register(struct rfkill *rfkill)
723{
724#ifdef CONFIG_RFKILL_LEDS
725 int error;
726
Dmitry Baryshkov7c4f4572008-07-22 14:17:37 +0400727 if (!rfkill->led_trigger.name)
728 rfkill->led_trigger.name = rfkill->dev.bus_id;
Dmitry Baryshkov96185662008-07-22 14:21:59 +0400729 if (!rfkill->led_trigger.activate)
730 rfkill->led_trigger.activate = rfkill_led_trigger_activate;
Michael Buesch135900c2007-09-27 21:33:12 +0200731 error = led_trigger_register(&rfkill->led_trigger);
732 if (error)
733 rfkill->led_trigger.name = NULL;
734#endif /* CONFIG_RFKILL_LEDS */
735}
736
737static void rfkill_led_trigger_unregister(struct rfkill *rfkill)
738{
739#ifdef CONFIG_RFKILL_LEDS
Henrique de Moraes Holschuh37f55e92008-07-21 21:18:18 -0300740 if (rfkill->led_trigger.name) {
Michael Buesch135900c2007-09-27 21:33:12 +0200741 led_trigger_unregister(&rfkill->led_trigger);
Henrique de Moraes Holschuh37f55e92008-07-21 21:18:18 -0300742 rfkill->led_trigger.name = NULL;
743 }
Michael Buesch135900c2007-09-27 21:33:12 +0200744#endif
745}
746
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700747/**
748 * rfkill_register - Register a rfkill structure.
749 * @rfkill: rfkill structure to be registered
750 *
751 * This function should be called by the network driver when the rfkill
752 * structure needs to be registered. Immediately from registration the
753 * switch driver should be able to service calls to toggle_radio.
754 */
Henrique de Moraes Holschuh77fba132008-08-02 15:10:59 -0300755int __must_check rfkill_register(struct rfkill *rfkill)
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700756{
757 static atomic_t rfkill_no = ATOMIC_INIT(0);
758 struct device *dev = &rfkill->dev;
759 int error;
760
Henrique de Moraes Holschuhf745ba02008-08-26 11:57:59 -0300761 if (WARN((!rfkill || !rfkill->toggle_radio ||
762 rfkill->type >= RFKILL_TYPE_MAX ||
763 rfkill->state >= RFKILL_STATE_MAX),
764 KERN_WARNING
765 "rfkill: attempt to register a "
766 "badly initialized rfkill struct\n"))
Henrique de Moraes Holschuh96c87602008-08-02 15:11:00 -0300767 return -EINVAL;
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700768
Michael Buesch8a8f1c02007-10-28 13:07:54 +0100769 snprintf(dev->bus_id, sizeof(dev->bus_id),
770 "rfkill%ld", (long)atomic_inc_return(&rfkill_no) - 1);
771
772 rfkill_led_trigger_register(rfkill);
773
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700774 error = rfkill_add_switch(rfkill);
Eric Paris632041f2008-01-13 16:20:56 -0500775 if (error) {
776 rfkill_led_trigger_unregister(rfkill);
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700777 return error;
Eric Paris632041f2008-01-13 16:20:56 -0500778 }
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700779
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700780 error = device_add(dev);
781 if (error) {
782 rfkill_remove_switch(rfkill);
Henrique de Moraes Holschuh37f55e92008-07-21 21:18:18 -0300783 rfkill_led_trigger_unregister(rfkill);
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700784 return error;
785 }
786
787 return 0;
788}
789EXPORT_SYMBOL(rfkill_register);
790
791/**
Henrique de Moraes Holschuhc8fcd902008-06-23 17:22:57 -0300792 * rfkill_unregister - Unregister a rfkill structure.
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700793 * @rfkill: rfkill structure to be unregistered
794 *
795 * This function should be called by the network driver during device
796 * teardown to destroy rfkill structure. Note that rfkill_free() should
797 * _not_ be called after rfkill_unregister().
798 */
799void rfkill_unregister(struct rfkill *rfkill)
800{
Henrique de Moraes Holschuhf745ba02008-08-26 11:57:59 -0300801 BUG_ON(!rfkill);
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700802 device_del(&rfkill->dev);
803 rfkill_remove_switch(rfkill);
Michael Buesch8a8f1c02007-10-28 13:07:54 +0100804 rfkill_led_trigger_unregister(rfkill);
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700805 put_device(&rfkill->dev);
806}
807EXPORT_SYMBOL(rfkill_unregister);
808
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300809/**
810 * rfkill_set_default - set initial value for a switch type
811 * @type - the type of switch to set the default state of
812 * @state - the new default state for that group of switches
813 *
814 * Sets the initial state rfkill should use for a given type.
815 * The following initial states are allowed: RFKILL_STATE_SOFT_BLOCKED
816 * and RFKILL_STATE_UNBLOCKED.
817 *
818 * This function is meant to be used by platform drivers for platforms
819 * that can save switch state across power down/reboot.
820 *
821 * The default state for each switch type can be changed exactly once.
822 * After a switch of that type is registered, the default state cannot
823 * be changed anymore. This guards against multiple drivers it the
824 * same platform trying to set the initial switch default state, which
825 * is not allowed.
826 *
827 * Returns -EPERM if the state has already been set once or is in use,
828 * so drivers likely want to either ignore or at most printk(KERN_NOTICE)
829 * if this function returns -EPERM.
830 *
831 * Returns 0 if the new default state was set, or an error if it
832 * could not be set.
833 */
834int rfkill_set_default(enum rfkill_type type, enum rfkill_state state)
835{
836 int error;
837
Henrique de Moraes Holschuhf745ba02008-08-26 11:57:59 -0300838 if (WARN((type >= RFKILL_TYPE_MAX ||
839 (state != RFKILL_STATE_SOFT_BLOCKED &&
840 state != RFKILL_STATE_UNBLOCKED)),
841 KERN_WARNING
842 "rfkill: illegal state %d or type %d passed as "
843 "parameter to rfkill_set_default\n", state, type))
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300844 return -EINVAL;
845
Henrique de Moraes Holschuh15635742008-08-26 11:58:00 -0300846 mutex_lock(&rfkill_global_mutex);
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300847
848 if (!test_and_set_bit(type, rfkill_states_lockdflt)) {
849 rfkill_global_states[type].default_state = state;
Henrique de Moraes Holschuh68d24132008-10-09 18:15:30 -0300850 rfkill_global_states[type].current_state = state;
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300851 error = 0;
852 } else
853 error = -EPERM;
854
Henrique de Moraes Holschuh15635742008-08-26 11:58:00 -0300855 mutex_unlock(&rfkill_global_mutex);
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300856 return error;
857}
858EXPORT_SYMBOL_GPL(rfkill_set_default);
859
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700860/*
861 * Rfkill module initialization/deinitialization.
862 */
863static int __init rfkill_init(void)
864{
865 int error;
866 int i;
867
Henrique de Moraes Holschuh5005657c2008-06-23 17:46:42 -0300868 /* RFKILL_STATE_HARD_BLOCKED is illegal here... */
869 if (rfkill_default_state != RFKILL_STATE_SOFT_BLOCKED &&
870 rfkill_default_state != RFKILL_STATE_UNBLOCKED)
Henrique de Moraes Holschuhe954b0b2008-06-23 17:22:59 -0300871 return -EINVAL;
872
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300873 for (i = 0; i < RFKILL_TYPE_MAX; i++)
874 rfkill_global_states[i].default_state = rfkill_default_state;
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700875
876 error = class_register(&rfkill_class);
877 if (error) {
878 printk(KERN_ERR "rfkill: unable to register rfkill class\n");
879 return error;
880 }
881
Henrique de Moraes Holschuhffb67c32008-06-23 17:23:05 -0300882 register_rfkill_notifier(&rfkill_blocking_uevent_nb);
883
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700884 return 0;
885}
886
887static void __exit rfkill_exit(void)
888{
Henrique de Moraes Holschuhffb67c32008-06-23 17:23:05 -0300889 unregister_rfkill_notifier(&rfkill_blocking_uevent_nb);
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700890 class_unregister(&rfkill_class);
891}
892
Michael Buesch2bf236d2007-10-28 14:39:02 +0100893subsys_initcall(rfkill_init);
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700894module_exit(rfkill_exit);