blob: 4f5a83183c95cd1de62da70d5ec0d117d641400e [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)];
Henrique de Moraes Holschuhd0039222008-10-09 21:49:33 -030054static bool rfkill_epo_lock_active;
Ivo van Doorncf4328c2007-05-07 00:34:20 -070055
Michael Buesch135900c2007-09-27 21:33:12 +020056
Simon Holm Thøgersenf32f8b72009-01-04 17:11:24 -080057#ifdef CONFIG_RFKILL_LEDS
Michael Buesch135900c2007-09-27 21:33:12 +020058static void rfkill_led_trigger(struct rfkill *rfkill,
59 enum rfkill_state state)
60{
Michael Buesch135900c2007-09-27 21:33:12 +020061 struct led_trigger *led = &rfkill->led_trigger;
62
63 if (!led->name)
64 return;
Henrique de Moraes Holschuh5005657c2008-06-23 17:46:42 -030065 if (state != RFKILL_STATE_UNBLOCKED)
Michael Buesch135900c2007-09-27 21:33:12 +020066 led_trigger_event(led, LED_OFF);
67 else
68 led_trigger_event(led, LED_FULL);
Michael Buesch135900c2007-09-27 21:33:12 +020069}
70
Dmitry Baryshkov96185662008-07-22 14:21:59 +040071static void rfkill_led_trigger_activate(struct led_classdev *led)
72{
73 struct rfkill *rfkill = container_of(led->trigger,
74 struct rfkill, led_trigger);
75
76 rfkill_led_trigger(rfkill, rfkill->state);
77}
Andrew Mortonaeca78b2009-04-24 15:26:02 -070078#else
79static inline void rfkill_led_trigger(struct rfkill *rfkill,
80 enum rfkill_state state)
81{
82}
Dmitry Baryshkov96185662008-07-22 14:21:59 +040083#endif /* CONFIG_RFKILL_LEDS */
84
Johannes Berg4dec9b82008-12-10 17:48:48 +010085static void rfkill_uevent(struct rfkill *rfkill)
Henrique de Moraes Holschuh79399a82008-06-23 17:23:03 -030086{
Johannes Berg4dec9b82008-12-10 17:48:48 +010087 kobject_uevent(&rfkill->dev.kobj, KOBJ_CHANGE);
Henrique de Moraes Holschuh79399a82008-06-23 17:23:03 -030088}
89
Henrique de Moraes Holschuh801e49a2008-06-23 17:23:00 -030090static void update_rfkill_state(struct rfkill *rfkill)
91{
Henrique de Moraes Holschuh79399a82008-06-23 17:23:03 -030092 enum rfkill_state newstate, oldstate;
Henrique de Moraes Holschuh801e49a2008-06-23 17:23:00 -030093
94 if (rfkill->get_state) {
95 mutex_lock(&rfkill->mutex);
Henrique de Moraes Holschuh79399a82008-06-23 17:23:03 -030096 if (!rfkill->get_state(rfkill->data, &newstate)) {
97 oldstate = rfkill->state;
Henrique de Moraes Holschuh801e49a2008-06-23 17:23:00 -030098 rfkill->state = newstate;
Henrique de Moraes Holschuh79399a82008-06-23 17:23:03 -030099 if (oldstate != newstate)
Johannes Berg4dec9b82008-12-10 17:48:48 +0100100 rfkill_uevent(rfkill);
Henrique de Moraes Holschuh79399a82008-06-23 17:23:03 -0300101 }
Henrique de Moraes Holschuh801e49a2008-06-23 17:23:00 -0300102 mutex_unlock(&rfkill->mutex);
103 }
Larry Finger492301f2009-04-09 22:14:19 -0500104 rfkill_led_trigger(rfkill, rfkill->state);
Henrique de Moraes Holschuh801e49a2008-06-23 17:23:00 -0300105}
106
Henrique de Moraes Holschuh5005657c2008-06-23 17:46:42 -0300107/**
108 * rfkill_toggle_radio - wrapper for toggle_radio hook
Henrique de Moraes Holschuh5005657c2008-06-23 17:46:42 -0300109 * @rfkill: the rfkill struct to use
110 * @force: calls toggle_radio even if cache says it is not needed,
111 * and also makes sure notifications of the state will be
112 * sent even if it didn't change
113 * @state: the new state to call toggle_radio() with
114 *
Henrique de Moraes Holschuh0f687e92008-07-03 13:14:56 -0300115 * Calls rfkill->toggle_radio, enforcing the API for toggle_radio
116 * calls and handling all the red tape such as issuing notifications
117 * if the call is successful.
118 *
Henrique de Moraes Holschuhe10e0df2008-08-02 14:56:25 -0300119 * Suspended devices are not touched at all, and -EAGAIN is returned.
120 *
Henrique de Moraes Holschuh435307a2008-07-21 21:18:22 -0300121 * Note that the @force parameter cannot override a (possibly cached)
122 * state of RFKILL_STATE_HARD_BLOCKED. Any device making use of
Henrique de Moraes Holschuh5005657c2008-06-23 17:46:42 -0300123 * RFKILL_STATE_HARD_BLOCKED implements either get_state() or
124 * rfkill_force_state(), so the cache either is bypassed or valid.
125 *
126 * Note that we do call toggle_radio for RFKILL_STATE_SOFT_BLOCKED
127 * even if the radio is in RFKILL_STATE_HARD_BLOCKED state, so as to
128 * give the driver a hint that it should double-BLOCK the transmitter.
129 *
Henrique de Moraes Holschuh064af112008-07-21 21:18:20 -0300130 * Caller must have acquired rfkill->mutex.
Henrique de Moraes Holschuh5005657c2008-06-23 17:46:42 -0300131 */
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700132static int rfkill_toggle_radio(struct rfkill *rfkill,
Henrique de Moraes Holschuh526324b2008-06-23 17:23:02 -0300133 enum rfkill_state state,
134 int force)
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700135{
Michael Buesch7f4c5342007-11-28 17:49:34 +0100136 int retval = 0;
Henrique de Moraes Holschuh801e49a2008-06-23 17:23:00 -0300137 enum rfkill_state oldstate, newstate;
138
Henrique de Moraes Holschuhe10e0df2008-08-02 14:56:25 -0300139 if (unlikely(rfkill->dev.power.power_state.event & PM_EVENT_SLEEP))
140 return -EBUSY;
141
Henrique de Moraes Holschuh801e49a2008-06-23 17:23:00 -0300142 oldstate = rfkill->state;
143
Henrique de Moraes Holschuh526324b2008-06-23 17:23:02 -0300144 if (rfkill->get_state && !force &&
Larry Finger492301f2009-04-09 22:14:19 -0500145 !rfkill->get_state(rfkill->data, &newstate)) {
Henrique de Moraes Holschuh801e49a2008-06-23 17:23:00 -0300146 rfkill->state = newstate;
Larry Finger492301f2009-04-09 22:14:19 -0500147 }
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700148
Henrique de Moraes Holschuh5005657c2008-06-23 17:46:42 -0300149 switch (state) {
150 case RFKILL_STATE_HARD_BLOCKED:
151 /* typically happens when refreshing hardware state,
152 * such as on resume */
153 state = RFKILL_STATE_SOFT_BLOCKED;
154 break;
155 case RFKILL_STATE_UNBLOCKED:
156 /* force can't override this, only rfkill_force_state() can */
157 if (rfkill->state == RFKILL_STATE_HARD_BLOCKED)
158 return -EPERM;
159 break;
160 case RFKILL_STATE_SOFT_BLOCKED:
161 /* nothing to do, we want to give drivers the hint to double
162 * BLOCK even a transmitter that is already in state
163 * RFKILL_STATE_HARD_BLOCKED */
164 break;
Henrique de Moraes Holschuh96c87602008-08-02 15:11:00 -0300165 default:
Henrique de Moraes Holschuhf745ba02008-08-26 11:57:59 -0300166 WARN(1, KERN_WARNING
167 "rfkill: illegal state %d passed as parameter "
168 "to rfkill_toggle_radio\n", state);
Henrique de Moraes Holschuh96c87602008-08-02 15:11:00 -0300169 return -EINVAL;
Henrique de Moraes Holschuh5005657c2008-06-23 17:46:42 -0300170 }
171
Henrique de Moraes Holschuh526324b2008-06-23 17:23:02 -0300172 if (force || state != rfkill->state) {
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700173 retval = rfkill->toggle_radio(rfkill->data, state);
Henrique de Moraes Holschuh5005657c2008-06-23 17:46:42 -0300174 /* never allow a HARD->SOFT downgrade! */
175 if (!retval && rfkill->state != RFKILL_STATE_HARD_BLOCKED)
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700176 rfkill->state = state;
177 }
178
Henrique de Moraes Holschuh417bd252008-10-03 16:58:05 -0300179 if (force || rfkill->state != oldstate)
Johannes Berg4dec9b82008-12-10 17:48:48 +0100180 rfkill_uevent(rfkill);
Henrique de Moraes Holschuh801e49a2008-06-23 17:23:00 -0300181
Larry Finger492301f2009-04-09 22:14:19 -0500182 rfkill_led_trigger(rfkill, rfkill->state);
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700183 return retval;
184}
185
186/**
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300187 * __rfkill_switch_all - Toggle state of all switches of given type
Henrique de Moraes Holschuh435307a2008-07-21 21:18:22 -0300188 * @type: type of interfaces to be affected
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700189 * @state: the new state
190 *
Henrique de Moraes Holschuh435307a2008-07-21 21:18:22 -0300191 * This function toggles the state of all switches of given type,
192 * unless a specific switch is claimed by userspace (in which case,
Henrique de Moraes Holschuhe10e0df2008-08-02 14:56:25 -0300193 * that switch is left alone) or suspended.
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300194 *
Henrique de Moraes Holschuh15635742008-08-26 11:58:00 -0300195 * Caller must have acquired rfkill_global_mutex.
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700196 */
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300197static void __rfkill_switch_all(const enum rfkill_type type,
198 const enum rfkill_state state)
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700199{
200 struct rfkill *rfkill;
201
Henrique de Moraes Holschuhf745ba02008-08-26 11:57:59 -0300202 if (WARN((state >= RFKILL_STATE_MAX || type >= RFKILL_TYPE_MAX),
203 KERN_WARNING
204 "rfkill: illegal state %d or type %d "
205 "passed as parameter to __rfkill_switch_all\n",
206 state, type))
Henrique de Moraes Holschuh96c87602008-08-02 15:11:00 -0300207 return;
208
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300209 rfkill_global_states[type].current_state = state;
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700210 list_for_each_entry(rfkill, &rfkill_list, node) {
Johannes Berg621cac82009-03-27 14:14:31 +0100211 if (rfkill->type == type) {
Henrique de Moraes Holschuh064af112008-07-21 21:18:20 -0300212 mutex_lock(&rfkill->mutex);
Henrique de Moraes Holschuh526324b2008-06-23 17:23:02 -0300213 rfkill_toggle_radio(rfkill, state, 0);
Henrique de Moraes Holschuh064af112008-07-21 21:18:20 -0300214 mutex_unlock(&rfkill->mutex);
Larry Finger492301f2009-04-09 22:14:19 -0500215 rfkill_led_trigger(rfkill, rfkill->state);
Henrique de Moraes Holschuh064af112008-07-21 21:18:20 -0300216 }
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700217 }
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300218}
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700219
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300220/**
221 * rfkill_switch_all - Toggle state of all switches of given type
222 * @type: type of interfaces to be affected
223 * @state: the new state
224 *
Henrique de Moraes Holschuh15635742008-08-26 11:58:00 -0300225 * Acquires rfkill_global_mutex and calls __rfkill_switch_all(@type, @state).
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300226 * Please refer to __rfkill_switch_all() for details.
Henrique de Moraes Holschuhd0039222008-10-09 21:49:33 -0300227 *
228 * Does nothing if the EPO lock is active.
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300229 */
230void rfkill_switch_all(enum rfkill_type type, enum rfkill_state state)
231{
Henrique de Moraes Holschuh15635742008-08-26 11:58:00 -0300232 mutex_lock(&rfkill_global_mutex);
Henrique de Moraes Holschuhd0039222008-10-09 21:49:33 -0300233 if (!rfkill_epo_lock_active)
234 __rfkill_switch_all(type, state);
Henrique de Moraes Holschuh15635742008-08-26 11:58:00 -0300235 mutex_unlock(&rfkill_global_mutex);
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700236}
237EXPORT_SYMBOL(rfkill_switch_all);
238
Henrique de Moraes Holschuh801e49a2008-06-23 17:23:00 -0300239/**
Henrique de Moraes Holschuh4081f002008-06-23 17:23:07 -0300240 * rfkill_epo - emergency power off all transmitters
241 *
Henrique de Moraes Holschuhe10e0df2008-08-02 14:56:25 -0300242 * This kicks all non-suspended rfkill devices to RFKILL_STATE_SOFT_BLOCKED,
Henrique de Moraes Holschuh15635742008-08-26 11:58:00 -0300243 * ignoring everything in its path but rfkill_global_mutex and rfkill->mutex.
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300244 *
245 * The global state before the EPO is saved and can be restored later
246 * using rfkill_restore_states().
Henrique de Moraes Holschuh4081f002008-06-23 17:23:07 -0300247 */
248void rfkill_epo(void)
249{
250 struct rfkill *rfkill;
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300251 int i;
Henrique de Moraes Holschuh4081f002008-06-23 17:23:07 -0300252
Henrique de Moraes Holschuh15635742008-08-26 11:58:00 -0300253 mutex_lock(&rfkill_global_mutex);
254
Henrique de Moraes Holschuhd0039222008-10-09 21:49:33 -0300255 rfkill_epo_lock_active = true;
Henrique de Moraes Holschuh4081f002008-06-23 17:23:07 -0300256 list_for_each_entry(rfkill, &rfkill_list, node) {
Henrique de Moraes Holschuh064af112008-07-21 21:18:20 -0300257 mutex_lock(&rfkill->mutex);
Henrique de Moraes Holschuh5005657c2008-06-23 17:46:42 -0300258 rfkill_toggle_radio(rfkill, RFKILL_STATE_SOFT_BLOCKED, 1);
Henrique de Moraes Holschuh064af112008-07-21 21:18:20 -0300259 mutex_unlock(&rfkill->mutex);
Henrique de Moraes Holschuh4081f002008-06-23 17:23:07 -0300260 }
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300261 for (i = 0; i < RFKILL_TYPE_MAX; i++) {
262 rfkill_global_states[i].default_state =
263 rfkill_global_states[i].current_state;
264 rfkill_global_states[i].current_state =
265 RFKILL_STATE_SOFT_BLOCKED;
266 }
Henrique de Moraes Holschuh15635742008-08-26 11:58:00 -0300267 mutex_unlock(&rfkill_global_mutex);
Larry Finger492301f2009-04-09 22:14:19 -0500268 rfkill_led_trigger(rfkill, rfkill->state);
Henrique de Moraes Holschuh4081f002008-06-23 17:23:07 -0300269}
270EXPORT_SYMBOL_GPL(rfkill_epo);
271
272/**
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300273 * rfkill_restore_states - restore global states
274 *
275 * Restore (and sync switches to) the global state from the
276 * states in rfkill_default_states. This can undo the effects of
277 * a call to rfkill_epo().
278 */
279void rfkill_restore_states(void)
280{
281 int i;
282
Henrique de Moraes Holschuh15635742008-08-26 11:58:00 -0300283 mutex_lock(&rfkill_global_mutex);
284
Henrique de Moraes Holschuhd0039222008-10-09 21:49:33 -0300285 rfkill_epo_lock_active = false;
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300286 for (i = 0; i < RFKILL_TYPE_MAX; i++)
287 __rfkill_switch_all(i, rfkill_global_states[i].default_state);
Henrique de Moraes Holschuh15635742008-08-26 11:58:00 -0300288 mutex_unlock(&rfkill_global_mutex);
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300289}
290EXPORT_SYMBOL_GPL(rfkill_restore_states);
291
292/**
Henrique de Moraes Holschuhd0039222008-10-09 21:49:33 -0300293 * rfkill_remove_epo_lock - unlock state changes
294 *
295 * Used by rfkill-input manually unlock state changes, when
296 * the EPO switch is deactivated.
297 */
298void rfkill_remove_epo_lock(void)
299{
300 mutex_lock(&rfkill_global_mutex);
301 rfkill_epo_lock_active = false;
302 mutex_unlock(&rfkill_global_mutex);
303}
304EXPORT_SYMBOL_GPL(rfkill_remove_epo_lock);
305
306/**
307 * rfkill_is_epo_lock_active - returns true EPO is active
308 *
309 * Returns 0 (false) if there is NOT an active EPO contidion,
310 * and 1 (true) if there is an active EPO contition, which
311 * locks all radios in one of the BLOCKED states.
312 *
313 * Can be called in atomic context.
314 */
315bool rfkill_is_epo_lock_active(void)
316{
317 return rfkill_epo_lock_active;
318}
319EXPORT_SYMBOL_GPL(rfkill_is_epo_lock_active);
320
321/**
Henrique de Moraes Holschuh68d24132008-10-09 18:15:30 -0300322 * rfkill_get_global_state - returns global state for a type
323 * @type: the type to get the global state of
324 *
325 * Returns the current global state for a given wireless
326 * device type.
327 */
328enum rfkill_state rfkill_get_global_state(const enum rfkill_type type)
329{
330 return rfkill_global_states[type].current_state;
331}
332EXPORT_SYMBOL_GPL(rfkill_get_global_state);
333
334/**
Henrique de Moraes Holschuh801e49a2008-06-23 17:23:00 -0300335 * rfkill_force_state - Force the internal rfkill radio state
336 * @rfkill: pointer to the rfkill class to modify.
337 * @state: the current radio state the class should be forced to.
338 *
339 * This function updates the internal state of the radio cached
340 * by the rfkill class. It should be used when the driver gets
341 * a notification by the firmware/hardware of the current *real*
342 * state of the radio rfkill switch.
343 *
Henrique de Moraes Holschuh2fd9b222008-07-21 21:18:17 -0300344 * Devices which are subject to external changes on their rfkill
345 * state (such as those caused by a hardware rfkill line) MUST
346 * have their driver arrange to call rfkill_force_state() as soon
347 * as possible after such a change.
348 *
349 * This function may not be called from an atomic context.
Henrique de Moraes Holschuh801e49a2008-06-23 17:23:00 -0300350 */
351int rfkill_force_state(struct rfkill *rfkill, enum rfkill_state state)
352{
Henrique de Moraes Holschuh79399a82008-06-23 17:23:03 -0300353 enum rfkill_state oldstate;
354
Henrique de Moraes Holschuhf745ba02008-08-26 11:57:59 -0300355 BUG_ON(!rfkill);
356 if (WARN((state >= RFKILL_STATE_MAX),
357 KERN_WARNING
358 "rfkill: illegal state %d passed as parameter "
359 "to rfkill_force_state\n", state))
Henrique de Moraes Holschuh801e49a2008-06-23 17:23:00 -0300360 return -EINVAL;
361
362 mutex_lock(&rfkill->mutex);
Henrique de Moraes Holschuh79399a82008-06-23 17:23:03 -0300363
364 oldstate = rfkill->state;
Henrique de Moraes Holschuh801e49a2008-06-23 17:23:00 -0300365 rfkill->state = state;
Henrique de Moraes Holschuh79399a82008-06-23 17:23:03 -0300366
367 if (state != oldstate)
Johannes Berg4dec9b82008-12-10 17:48:48 +0100368 rfkill_uevent(rfkill);
Henrique de Moraes Holschuh79399a82008-06-23 17:23:03 -0300369
Henrique de Moraes Holschuh801e49a2008-06-23 17:23:00 -0300370 mutex_unlock(&rfkill->mutex);
Larry Finger492301f2009-04-09 22:14:19 -0500371 rfkill_led_trigger(rfkill, rfkill->state);
Henrique de Moraes Holschuh801e49a2008-06-23 17:23:00 -0300372
373 return 0;
374}
375EXPORT_SYMBOL(rfkill_force_state);
376
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700377static ssize_t rfkill_name_show(struct device *dev,
378 struct device_attribute *attr,
379 char *buf)
380{
381 struct rfkill *rfkill = to_rfkill(dev);
382
383 return sprintf(buf, "%s\n", rfkill->name);
384}
385
Henrique de Moraes Holschuh99c632e2008-06-23 17:23:04 -0300386static const char *rfkill_get_type_str(enum rfkill_type type)
387{
388 switch (type) {
389 case RFKILL_TYPE_WLAN:
390 return "wlan";
391 case RFKILL_TYPE_BLUETOOTH:
392 return "bluetooth";
393 case RFKILL_TYPE_UWB:
394 return "ultrawideband";
395 case RFKILL_TYPE_WIMAX:
396 return "wimax";
397 case RFKILL_TYPE_WWAN:
398 return "wwan";
399 default:
400 BUG();
401 }
402}
403
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700404static ssize_t rfkill_type_show(struct device *dev,
405 struct device_attribute *attr,
406 char *buf)
407{
408 struct rfkill *rfkill = to_rfkill(dev);
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700409
Henrique de Moraes Holschuh99c632e2008-06-23 17:23:04 -0300410 return sprintf(buf, "%s\n", rfkill_get_type_str(rfkill->type));
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700411}
412
413static ssize_t rfkill_state_show(struct device *dev,
414 struct device_attribute *attr,
415 char *buf)
416{
417 struct rfkill *rfkill = to_rfkill(dev);
418
Henrique de Moraes Holschuh801e49a2008-06-23 17:23:00 -0300419 update_rfkill_state(rfkill);
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700420 return sprintf(buf, "%d\n", rfkill->state);
421}
422
423static ssize_t rfkill_state_store(struct device *dev,
424 struct device_attribute *attr,
425 const char *buf, size_t count)
426{
427 struct rfkill *rfkill = to_rfkill(dev);
Henrique de Moraes Holschuh849e0572008-08-26 11:57:57 -0300428 unsigned long state;
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700429 int error;
430
431 if (!capable(CAP_NET_ADMIN))
432 return -EPERM;
433
Henrique de Moraes Holschuh849e0572008-08-26 11:57:57 -0300434 error = strict_strtoul(buf, 0, &state);
435 if (error)
436 return error;
437
Henrique de Moraes Holschuh5005657c2008-06-23 17:46:42 -0300438 /* RFKILL_STATE_HARD_BLOCKED is illegal here... */
439 if (state != RFKILL_STATE_UNBLOCKED &&
440 state != RFKILL_STATE_SOFT_BLOCKED)
441 return -EINVAL;
442
Henrique de Moraes Holschuhcf4b4aa2008-10-09 18:15:29 -0300443 error = mutex_lock_killable(&rfkill->mutex);
444 if (error)
445 return error;
Henrique de Moraes Holschuhd0039222008-10-09 21:49:33 -0300446
447 if (!rfkill_epo_lock_active)
448 error = rfkill_toggle_radio(rfkill, state, 0);
449 else
450 error = -EPERM;
451
Michael Buesch7f4c5342007-11-28 17:49:34 +0100452 mutex_unlock(&rfkill->mutex);
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700453
Michael Buesch7f4c5342007-11-28 17:49:34 +0100454 return error ? error : count;
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700455}
456
457static ssize_t rfkill_claim_show(struct device *dev,
458 struct device_attribute *attr,
459 char *buf)
460{
Johannes Berg621cac82009-03-27 14:14:31 +0100461 return sprintf(buf, "%d\n", 0);
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700462}
463
464static ssize_t rfkill_claim_store(struct device *dev,
465 struct device_attribute *attr,
466 const char *buf, size_t count)
467{
Johannes Berg621cac82009-03-27 14:14:31 +0100468 return -EOPNOTSUPP;
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700469}
470
471static struct device_attribute rfkill_dev_attrs[] = {
472 __ATTR(name, S_IRUGO, rfkill_name_show, NULL),
473 __ATTR(type, S_IRUGO, rfkill_type_show, NULL),
Ivo van Doornc81de6a2007-07-18 15:38:03 -0700474 __ATTR(state, S_IRUGO|S_IWUSR, rfkill_state_show, rfkill_state_store),
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700475 __ATTR(claim, S_IRUGO|S_IWUSR, rfkill_claim_show, rfkill_claim_store),
476 __ATTR_NULL
477};
478
479static void rfkill_release(struct device *dev)
480{
481 struct rfkill *rfkill = to_rfkill(dev);
482
483 kfree(rfkill);
484 module_put(THIS_MODULE);
485}
486
487#ifdef CONFIG_PM
488static int rfkill_suspend(struct device *dev, pm_message_t state)
489{
Henrique de Moraes Holschuhf80b5e92008-11-21 20:40:09 -0200490 struct rfkill *rfkill = to_rfkill(dev);
491
Henrique de Moraes Holschuhbed7aac2008-08-26 11:58:01 -0300492 /* mark class device as suspended */
493 if (dev->power.power_state.event != state.event)
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700494 dev->power.power_state = state;
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700495
Henrique de Moraes Holschuhf80b5e92008-11-21 20:40:09 -0200496 /* store state for the resume handler */
497 rfkill->state_for_resume = rfkill->state;
498
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700499 return 0;
500}
501
502static int rfkill_resume(struct device *dev)
503{
504 struct rfkill *rfkill = to_rfkill(dev);
Henrique de Moraes Holschuh24689c82008-11-21 20:40:10 -0200505 enum rfkill_state newstate;
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700506
507 if (dev->power.power_state.event != PM_EVENT_ON) {
508 mutex_lock(&rfkill->mutex);
509
Henrique de Moraes Holschuhe10e0df2008-08-02 14:56:25 -0300510 dev->power.power_state.event = PM_EVENT_ON;
511
Henrique de Moraes Holschuh17670792008-10-09 18:15:32 -0300512 /*
Henrique de Moraes Holschuh24689c82008-11-21 20:40:10 -0200513 * rfkill->state could have been modified before we got
514 * called, and won't be updated by rfkill_toggle_radio()
515 * in force mode. Sync it FIRST.
516 */
517 if (rfkill->get_state &&
518 !rfkill->get_state(rfkill->data, &newstate))
519 rfkill->state = newstate;
520
521 /*
Henrique de Moraes Holschuh17670792008-10-09 18:15:32 -0300522 * If we are under EPO, kick transmitter offline,
523 * otherwise restore to pre-suspend state.
524 *
525 * Issue a notification in any case
526 */
527 rfkill_toggle_radio(rfkill,
528 rfkill_epo_lock_active ?
529 RFKILL_STATE_SOFT_BLOCKED :
Henrique de Moraes Holschuhf80b5e92008-11-21 20:40:09 -0200530 rfkill->state_for_resume,
Henrique de Moraes Holschuh17670792008-10-09 18:15:32 -0300531 1);
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700532
533 mutex_unlock(&rfkill->mutex);
Larry Finger492301f2009-04-09 22:14:19 -0500534 rfkill_led_trigger(rfkill, rfkill->state);
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700535 }
536
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700537 return 0;
538}
539#else
540#define rfkill_suspend NULL
541#define rfkill_resume NULL
542#endif
543
Henrique de Moraes Holschuhffb67c32008-06-23 17:23:05 -0300544static int rfkill_dev_uevent(struct device *dev, struct kobj_uevent_env *env)
545{
546 struct rfkill *rfkill = to_rfkill(dev);
547 int error;
548
549 error = add_uevent_var(env, "RFKILL_NAME=%s", rfkill->name);
550 if (error)
551 return error;
552 error = add_uevent_var(env, "RFKILL_TYPE=%s",
553 rfkill_get_type_str(rfkill->type));
554 if (error)
555 return error;
556 error = add_uevent_var(env, "RFKILL_STATE=%d", rfkill->state);
557 return error;
558}
559
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700560static struct class rfkill_class = {
561 .name = "rfkill",
562 .dev_release = rfkill_release,
563 .dev_attrs = rfkill_dev_attrs,
564 .suspend = rfkill_suspend,
565 .resume = rfkill_resume,
Henrique de Moraes Holschuhffb67c32008-06-23 17:23:05 -0300566 .dev_uevent = rfkill_dev_uevent,
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700567};
568
Henrique de Moraes Holschuh02589f62008-08-02 15:10:57 -0300569static int rfkill_check_duplicity(const struct rfkill *rfkill)
570{
571 struct rfkill *p;
572 unsigned long seen[BITS_TO_LONGS(RFKILL_TYPE_MAX)];
573
574 memset(seen, 0, sizeof(seen));
575
576 list_for_each_entry(p, &rfkill_list, node) {
Henrique de Moraes Holschuhf745ba02008-08-26 11:57:59 -0300577 if (WARN((p == rfkill), KERN_WARNING
578 "rfkill: illegal attempt to register "
579 "an already registered rfkill struct\n"))
Henrique de Moraes Holschuh02589f62008-08-02 15:10:57 -0300580 return -EEXIST;
Henrique de Moraes Holschuh02589f62008-08-02 15:10:57 -0300581 set_bit(p->type, seen);
582 }
583
584 /* 0: first switch of its kind */
Jonathan McDowell4a9d9162008-10-30 22:46:48 +0000585 return (test_bit(rfkill->type, seen)) ? 1 : 0;
Henrique de Moraes Holschuh02589f62008-08-02 15:10:57 -0300586}
587
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700588static int rfkill_add_switch(struct rfkill *rfkill)
589{
Henrique de Moraes Holschuh02589f62008-08-02 15:10:57 -0300590 int error;
591
Henrique de Moraes Holschuh15635742008-08-26 11:58:00 -0300592 mutex_lock(&rfkill_global_mutex);
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700593
Henrique de Moraes Holschuh02589f62008-08-02 15:10:57 -0300594 error = rfkill_check_duplicity(rfkill);
595 if (error < 0)
596 goto unlock_out;
597
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300598 if (!error) {
599 /* lock default after first use */
600 set_bit(rfkill->type, rfkill_states_lockdflt);
601 rfkill_global_states[rfkill->type].current_state =
602 rfkill_global_states[rfkill->type].default_state;
603 }
604
605 rfkill_toggle_radio(rfkill,
606 rfkill_global_states[rfkill->type].current_state,
607 0);
Henrique de Moraes Holschuhfd4484a2008-07-03 13:14:57 -0300608
609 list_add_tail(&rfkill->node, &rfkill_list);
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700610
Henrique de Moraes Holschuh02589f62008-08-02 15:10:57 -0300611 error = 0;
612unlock_out:
Henrique de Moraes Holschuh15635742008-08-26 11:58:00 -0300613 mutex_unlock(&rfkill_global_mutex);
Michael Buesch7319f1e2007-10-28 15:16:50 +0100614
Henrique de Moraes Holschuh02589f62008-08-02 15:10:57 -0300615 return error;
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700616}
617
618static void rfkill_remove_switch(struct rfkill *rfkill)
619{
Henrique de Moraes Holschuh15635742008-08-26 11:58:00 -0300620 mutex_lock(&rfkill_global_mutex);
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700621 list_del_init(&rfkill->node);
Henrique de Moraes Holschuh15635742008-08-26 11:58:00 -0300622 mutex_unlock(&rfkill_global_mutex);
Henrique de Moraes Holschuh064af112008-07-21 21:18:20 -0300623
624 mutex_lock(&rfkill->mutex);
625 rfkill_toggle_radio(rfkill, RFKILL_STATE_SOFT_BLOCKED, 1);
626 mutex_unlock(&rfkill->mutex);
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700627}
628
629/**
630 * rfkill_allocate - allocate memory for rfkill structure.
631 * @parent: device that has rf switch on it
Ivo van Doorn234a0ca2007-09-13 09:20:42 +0200632 * @type: type of the switch (RFKILL_TYPE_*)
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700633 *
634 * This function should be called by the network driver when it needs
Henrique de Moraes Holschuh435307a2008-07-21 21:18:22 -0300635 * rfkill structure. Once the structure is allocated the driver should
636 * finish its initialization by setting the name, private data, enable_radio
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700637 * and disable_radio methods and then register it with rfkill_register().
Henrique de Moraes Holschuh435307a2008-07-21 21:18:22 -0300638 *
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700639 * NOTE: If registration fails the structure shoudl be freed by calling
640 * rfkill_free() otherwise rfkill_unregister() should be used.
641 */
Henrique de Moraes Holschuh77fba132008-08-02 15:10:59 -0300642struct rfkill * __must_check rfkill_allocate(struct device *parent,
643 enum rfkill_type type)
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700644{
645 struct rfkill *rfkill;
646 struct device *dev;
647
Henrique de Moraes Holschuhf745ba02008-08-26 11:57:59 -0300648 if (WARN((type >= RFKILL_TYPE_MAX),
649 KERN_WARNING
650 "rfkill: illegal type %d passed as parameter "
651 "to rfkill_allocate\n", type))
652 return NULL;
653
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700654 rfkill = kzalloc(sizeof(struct rfkill), GFP_KERNEL);
Ivo van Doornd007da12007-05-19 12:24:39 -0700655 if (!rfkill)
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700656 return NULL;
657
658 mutex_init(&rfkill->mutex);
659 INIT_LIST_HEAD(&rfkill->node);
660 rfkill->type = type;
661
662 dev = &rfkill->dev;
663 dev->class = &rfkill_class;
664 dev->parent = parent;
665 device_initialize(dev);
666
667 __module_get(THIS_MODULE);
668
669 return rfkill;
670}
671EXPORT_SYMBOL(rfkill_allocate);
672
673/**
674 * rfkill_free - Mark rfkill structure for deletion
675 * @rfkill: rfkill structure to be destroyed
676 *
Henrique de Moraes Holschuh435307a2008-07-21 21:18:22 -0300677 * Decrements reference count of the rfkill structure so it is destroyed.
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700678 * Note that rfkill_free() should _not_ be called after rfkill_unregister().
679 */
680void rfkill_free(struct rfkill *rfkill)
681{
682 if (rfkill)
683 put_device(&rfkill->dev);
684}
685EXPORT_SYMBOL(rfkill_free);
686
Michael Buesch135900c2007-09-27 21:33:12 +0200687static void rfkill_led_trigger_register(struct rfkill *rfkill)
688{
689#ifdef CONFIG_RFKILL_LEDS
690 int error;
691
Dmitry Baryshkov7c4f4572008-07-22 14:17:37 +0400692 if (!rfkill->led_trigger.name)
Kay Sieversfb28ad32008-11-10 13:55:14 -0800693 rfkill->led_trigger.name = dev_name(&rfkill->dev);
Dmitry Baryshkov96185662008-07-22 14:21:59 +0400694 if (!rfkill->led_trigger.activate)
695 rfkill->led_trigger.activate = rfkill_led_trigger_activate;
Michael Buesch135900c2007-09-27 21:33:12 +0200696 error = led_trigger_register(&rfkill->led_trigger);
697 if (error)
698 rfkill->led_trigger.name = NULL;
699#endif /* CONFIG_RFKILL_LEDS */
700}
701
702static void rfkill_led_trigger_unregister(struct rfkill *rfkill)
703{
704#ifdef CONFIG_RFKILL_LEDS
Henrique de Moraes Holschuh37f55e92008-07-21 21:18:18 -0300705 if (rfkill->led_trigger.name) {
Michael Buesch135900c2007-09-27 21:33:12 +0200706 led_trigger_unregister(&rfkill->led_trigger);
Henrique de Moraes Holschuh37f55e92008-07-21 21:18:18 -0300707 rfkill->led_trigger.name = NULL;
708 }
Michael Buesch135900c2007-09-27 21:33:12 +0200709#endif
710}
711
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700712/**
713 * rfkill_register - Register a rfkill structure.
714 * @rfkill: rfkill structure to be registered
715 *
716 * This function should be called by the network driver when the rfkill
717 * structure needs to be registered. Immediately from registration the
718 * switch driver should be able to service calls to toggle_radio.
719 */
Henrique de Moraes Holschuh77fba132008-08-02 15:10:59 -0300720int __must_check rfkill_register(struct rfkill *rfkill)
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700721{
722 static atomic_t rfkill_no = ATOMIC_INIT(0);
723 struct device *dev = &rfkill->dev;
724 int error;
725
Henrique de Moraes Holschuhf745ba02008-08-26 11:57:59 -0300726 if (WARN((!rfkill || !rfkill->toggle_radio ||
727 rfkill->type >= RFKILL_TYPE_MAX ||
728 rfkill->state >= RFKILL_STATE_MAX),
729 KERN_WARNING
730 "rfkill: attempt to register a "
731 "badly initialized rfkill struct\n"))
Henrique de Moraes Holschuh96c87602008-08-02 15:11:00 -0300732 return -EINVAL;
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700733
Kay Sieversfb28ad32008-11-10 13:55:14 -0800734 dev_set_name(dev, "rfkill%ld", (long)atomic_inc_return(&rfkill_no) - 1);
Michael Buesch8a8f1c02007-10-28 13:07:54 +0100735
736 rfkill_led_trigger_register(rfkill);
737
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700738 error = rfkill_add_switch(rfkill);
Eric Paris632041f2008-01-13 16:20:56 -0500739 if (error) {
740 rfkill_led_trigger_unregister(rfkill);
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700741 return error;
Eric Paris632041f2008-01-13 16:20:56 -0500742 }
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700743
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700744 error = device_add(dev);
745 if (error) {
746 rfkill_remove_switch(rfkill);
Henrique de Moraes Holschuh37f55e92008-07-21 21:18:18 -0300747 rfkill_led_trigger_unregister(rfkill);
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700748 return error;
749 }
750
751 return 0;
752}
753EXPORT_SYMBOL(rfkill_register);
754
755/**
Henrique de Moraes Holschuhc8fcd902008-06-23 17:22:57 -0300756 * rfkill_unregister - Unregister a rfkill structure.
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700757 * @rfkill: rfkill structure to be unregistered
758 *
759 * This function should be called by the network driver during device
760 * teardown to destroy rfkill structure. Note that rfkill_free() should
761 * _not_ be called after rfkill_unregister().
762 */
763void rfkill_unregister(struct rfkill *rfkill)
764{
Henrique de Moraes Holschuhf745ba02008-08-26 11:57:59 -0300765 BUG_ON(!rfkill);
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700766 device_del(&rfkill->dev);
767 rfkill_remove_switch(rfkill);
Michael Buesch8a8f1c02007-10-28 13:07:54 +0100768 rfkill_led_trigger_unregister(rfkill);
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700769 put_device(&rfkill->dev);
770}
771EXPORT_SYMBOL(rfkill_unregister);
772
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300773/**
774 * rfkill_set_default - set initial value for a switch type
775 * @type - the type of switch to set the default state of
776 * @state - the new default state for that group of switches
777 *
778 * Sets the initial state rfkill should use for a given type.
779 * The following initial states are allowed: RFKILL_STATE_SOFT_BLOCKED
780 * and RFKILL_STATE_UNBLOCKED.
781 *
782 * This function is meant to be used by platform drivers for platforms
783 * that can save switch state across power down/reboot.
784 *
785 * The default state for each switch type can be changed exactly once.
786 * After a switch of that type is registered, the default state cannot
787 * be changed anymore. This guards against multiple drivers it the
788 * same platform trying to set the initial switch default state, which
789 * is not allowed.
790 *
791 * Returns -EPERM if the state has already been set once or is in use,
792 * so drivers likely want to either ignore or at most printk(KERN_NOTICE)
793 * if this function returns -EPERM.
794 *
795 * Returns 0 if the new default state was set, or an error if it
796 * could not be set.
797 */
798int rfkill_set_default(enum rfkill_type type, enum rfkill_state state)
799{
800 int error;
801
Henrique de Moraes Holschuhf745ba02008-08-26 11:57:59 -0300802 if (WARN((type >= RFKILL_TYPE_MAX ||
803 (state != RFKILL_STATE_SOFT_BLOCKED &&
804 state != RFKILL_STATE_UNBLOCKED)),
805 KERN_WARNING
806 "rfkill: illegal state %d or type %d passed as "
807 "parameter to rfkill_set_default\n", state, type))
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300808 return -EINVAL;
809
Henrique de Moraes Holschuh15635742008-08-26 11:58:00 -0300810 mutex_lock(&rfkill_global_mutex);
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300811
812 if (!test_and_set_bit(type, rfkill_states_lockdflt)) {
813 rfkill_global_states[type].default_state = state;
Henrique de Moraes Holschuh68d24132008-10-09 18:15:30 -0300814 rfkill_global_states[type].current_state = state;
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300815 error = 0;
816 } else
817 error = -EPERM;
818
Henrique de Moraes Holschuh15635742008-08-26 11:58:00 -0300819 mutex_unlock(&rfkill_global_mutex);
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300820 return error;
821}
822EXPORT_SYMBOL_GPL(rfkill_set_default);
823
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700824/*
825 * Rfkill module initialization/deinitialization.
826 */
827static int __init rfkill_init(void)
828{
829 int error;
830 int i;
831
Henrique de Moraes Holschuh5005657c2008-06-23 17:46:42 -0300832 /* RFKILL_STATE_HARD_BLOCKED is illegal here... */
833 if (rfkill_default_state != RFKILL_STATE_SOFT_BLOCKED &&
834 rfkill_default_state != RFKILL_STATE_UNBLOCKED)
Henrique de Moraes Holschuhe954b0b2008-06-23 17:22:59 -0300835 return -EINVAL;
836
Henrique de Moraes Holschuh99619202008-08-02 15:10:58 -0300837 for (i = 0; i < RFKILL_TYPE_MAX; i++)
838 rfkill_global_states[i].default_state = rfkill_default_state;
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700839
840 error = class_register(&rfkill_class);
841 if (error) {
842 printk(KERN_ERR "rfkill: unable to register rfkill class\n");
843 return error;
844 }
845
846 return 0;
847}
848
849static void __exit rfkill_exit(void)
850{
851 class_unregister(&rfkill_class);
852}
853
Michael Buesch2bf236d2007-10-28 14:39:02 +0100854subsys_initcall(rfkill_init);
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700855module_exit(rfkill_exit);