Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 1 | /* |
Ivo van Doorn | fe242cf | 2007-09-27 14:57:05 -0700 | [diff] [blame] | 2 | * Copyright (C) 2006 - 2007 Ivo van Doorn |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 3 | * 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 Buesch | 2736622 | 2007-11-02 20:18:11 +0100 | [diff] [blame] | 30 | /* Get declaration of rfkill_switch_all() to shut up sparse. */ |
| 31 | #include "rfkill-input.h" |
| 32 | |
| 33 | |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 34 | MODULE_AUTHOR("Ivo van Doorn <IvDoorn@gmail.com>"); |
| 35 | MODULE_VERSION("1.0"); |
| 36 | MODULE_DESCRIPTION("RF switch support"); |
| 37 | MODULE_LICENSE("GPL"); |
| 38 | |
| 39 | static LIST_HEAD(rfkill_list); /* list of registered rf switches */ |
| 40 | static DEFINE_MUTEX(rfkill_mutex); |
| 41 | |
Henrique de Moraes Holschuh | e954b0b | 2008-06-23 17:22:59 -0300 | [diff] [blame^] | 42 | static unsigned int rfkill_default_state = RFKILL_STATE_ON; |
| 43 | module_param_named(default_state, rfkill_default_state, uint, 0444); |
| 44 | MODULE_PARM_DESC(default_state, |
| 45 | "Default initial state for all radio types, 0 = radio off"); |
| 46 | |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 47 | static enum rfkill_state rfkill_states[RFKILL_TYPE_MAX]; |
| 48 | |
Michael Buesch | 135900c | 2007-09-27 21:33:12 +0200 | [diff] [blame] | 49 | |
| 50 | static void rfkill_led_trigger(struct rfkill *rfkill, |
| 51 | enum rfkill_state state) |
| 52 | { |
| 53 | #ifdef CONFIG_RFKILL_LEDS |
| 54 | struct led_trigger *led = &rfkill->led_trigger; |
| 55 | |
| 56 | if (!led->name) |
| 57 | return; |
| 58 | if (state == RFKILL_STATE_OFF) |
| 59 | led_trigger_event(led, LED_OFF); |
| 60 | else |
| 61 | led_trigger_event(led, LED_FULL); |
| 62 | #endif /* CONFIG_RFKILL_LEDS */ |
| 63 | } |
| 64 | |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 65 | static int rfkill_toggle_radio(struct rfkill *rfkill, |
| 66 | enum rfkill_state state) |
| 67 | { |
Michael Buesch | 7f4c534 | 2007-11-28 17:49:34 +0100 | [diff] [blame] | 68 | int retval = 0; |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 69 | |
| 70 | if (state != rfkill->state) { |
| 71 | retval = rfkill->toggle_radio(rfkill->data, state); |
Michael Buesch | 135900c | 2007-09-27 21:33:12 +0200 | [diff] [blame] | 72 | if (!retval) { |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 73 | rfkill->state = state; |
Michael Buesch | 135900c | 2007-09-27 21:33:12 +0200 | [diff] [blame] | 74 | rfkill_led_trigger(rfkill, state); |
| 75 | } |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 78 | return retval; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * rfkill_switch_all - Toggle state of all switches of given type |
| 83 | * @type: type of interfaces to be affeceted |
| 84 | * @state: the new state |
| 85 | * |
| 86 | * This function toggles state of all switches of given type unless |
| 87 | * a specific switch is claimed by userspace in which case it is |
| 88 | * left alone. |
| 89 | */ |
| 90 | |
| 91 | void rfkill_switch_all(enum rfkill_type type, enum rfkill_state state) |
| 92 | { |
| 93 | struct rfkill *rfkill; |
| 94 | |
| 95 | mutex_lock(&rfkill_mutex); |
| 96 | |
| 97 | rfkill_states[type] = state; |
| 98 | |
| 99 | list_for_each_entry(rfkill, &rfkill_list, node) { |
Carlos Corbacho | 89796f6 | 2008-04-12 16:39:47 +0100 | [diff] [blame] | 100 | if ((!rfkill->user_claim) && (rfkill->type == type)) |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 101 | rfkill_toggle_radio(rfkill, state); |
| 102 | } |
| 103 | |
| 104 | mutex_unlock(&rfkill_mutex); |
| 105 | } |
| 106 | EXPORT_SYMBOL(rfkill_switch_all); |
| 107 | |
| 108 | static ssize_t rfkill_name_show(struct device *dev, |
| 109 | struct device_attribute *attr, |
| 110 | char *buf) |
| 111 | { |
| 112 | struct rfkill *rfkill = to_rfkill(dev); |
| 113 | |
| 114 | return sprintf(buf, "%s\n", rfkill->name); |
| 115 | } |
| 116 | |
| 117 | static ssize_t rfkill_type_show(struct device *dev, |
| 118 | struct device_attribute *attr, |
| 119 | char *buf) |
| 120 | { |
| 121 | struct rfkill *rfkill = to_rfkill(dev); |
| 122 | const char *type; |
| 123 | |
| 124 | switch (rfkill->type) { |
| 125 | case RFKILL_TYPE_WLAN: |
| 126 | type = "wlan"; |
| 127 | break; |
| 128 | case RFKILL_TYPE_BLUETOOTH: |
| 129 | type = "bluetooth"; |
| 130 | break; |
Ivo van Doorn | e0665486 | 2007-09-13 09:21:31 +0200 | [diff] [blame] | 131 | case RFKILL_TYPE_UWB: |
| 132 | type = "ultrawideband"; |
| 133 | break; |
Iñaky Pérez-González | 303d9bf | 2008-01-23 13:40:27 -0800 | [diff] [blame] | 134 | case RFKILL_TYPE_WIMAX: |
| 135 | type = "wimax"; |
| 136 | break; |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 137 | default: |
| 138 | BUG(); |
| 139 | } |
| 140 | |
| 141 | return sprintf(buf, "%s\n", type); |
| 142 | } |
| 143 | |
| 144 | static ssize_t rfkill_state_show(struct device *dev, |
| 145 | struct device_attribute *attr, |
| 146 | char *buf) |
| 147 | { |
| 148 | struct rfkill *rfkill = to_rfkill(dev); |
| 149 | |
| 150 | return sprintf(buf, "%d\n", rfkill->state); |
| 151 | } |
| 152 | |
| 153 | static ssize_t rfkill_state_store(struct device *dev, |
| 154 | struct device_attribute *attr, |
| 155 | const char *buf, size_t count) |
| 156 | { |
| 157 | struct rfkill *rfkill = to_rfkill(dev); |
| 158 | unsigned int state = simple_strtoul(buf, NULL, 0); |
| 159 | int error; |
| 160 | |
| 161 | if (!capable(CAP_NET_ADMIN)) |
| 162 | return -EPERM; |
| 163 | |
Michael Buesch | 7f4c534 | 2007-11-28 17:49:34 +0100 | [diff] [blame] | 164 | if (mutex_lock_interruptible(&rfkill->mutex)) |
| 165 | return -ERESTARTSYS; |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 166 | error = rfkill_toggle_radio(rfkill, |
| 167 | state ? RFKILL_STATE_ON : RFKILL_STATE_OFF); |
Michael Buesch | 7f4c534 | 2007-11-28 17:49:34 +0100 | [diff] [blame] | 168 | mutex_unlock(&rfkill->mutex); |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 169 | |
Michael Buesch | 7f4c534 | 2007-11-28 17:49:34 +0100 | [diff] [blame] | 170 | return error ? error : count; |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | static ssize_t rfkill_claim_show(struct device *dev, |
| 174 | struct device_attribute *attr, |
| 175 | char *buf) |
| 176 | { |
| 177 | struct rfkill *rfkill = to_rfkill(dev); |
| 178 | |
| 179 | return sprintf(buf, "%d", rfkill->user_claim); |
| 180 | } |
| 181 | |
| 182 | static ssize_t rfkill_claim_store(struct device *dev, |
| 183 | struct device_attribute *attr, |
| 184 | const char *buf, size_t count) |
| 185 | { |
| 186 | struct rfkill *rfkill = to_rfkill(dev); |
| 187 | bool claim = !!simple_strtoul(buf, NULL, 0); |
| 188 | int error; |
| 189 | |
| 190 | if (!capable(CAP_NET_ADMIN)) |
| 191 | return -EPERM; |
| 192 | |
| 193 | /* |
| 194 | * Take the global lock to make sure the kernel is not in |
| 195 | * the middle of rfkill_switch_all |
| 196 | */ |
| 197 | error = mutex_lock_interruptible(&rfkill_mutex); |
| 198 | if (error) |
| 199 | return error; |
| 200 | |
Michael Buesch | 20405c0 | 2007-09-27 21:34:23 +0200 | [diff] [blame] | 201 | if (rfkill->user_claim_unsupported) { |
| 202 | error = -EOPNOTSUPP; |
| 203 | goto out_unlock; |
| 204 | } |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 205 | if (rfkill->user_claim != claim) { |
| 206 | if (!claim) |
| 207 | rfkill_toggle_radio(rfkill, |
| 208 | rfkill_states[rfkill->type]); |
| 209 | rfkill->user_claim = claim; |
| 210 | } |
| 211 | |
Michael Buesch | 20405c0 | 2007-09-27 21:34:23 +0200 | [diff] [blame] | 212 | out_unlock: |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 213 | mutex_unlock(&rfkill_mutex); |
| 214 | |
Michael Buesch | 20405c0 | 2007-09-27 21:34:23 +0200 | [diff] [blame] | 215 | return error ? error : count; |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | static struct device_attribute rfkill_dev_attrs[] = { |
| 219 | __ATTR(name, S_IRUGO, rfkill_name_show, NULL), |
| 220 | __ATTR(type, S_IRUGO, rfkill_type_show, NULL), |
Ivo van Doorn | c81de6a | 2007-07-18 15:38:03 -0700 | [diff] [blame] | 221 | __ATTR(state, S_IRUGO|S_IWUSR, rfkill_state_show, rfkill_state_store), |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 222 | __ATTR(claim, S_IRUGO|S_IWUSR, rfkill_claim_show, rfkill_claim_store), |
| 223 | __ATTR_NULL |
| 224 | }; |
| 225 | |
| 226 | static void rfkill_release(struct device *dev) |
| 227 | { |
| 228 | struct rfkill *rfkill = to_rfkill(dev); |
| 229 | |
| 230 | kfree(rfkill); |
| 231 | module_put(THIS_MODULE); |
| 232 | } |
| 233 | |
| 234 | #ifdef CONFIG_PM |
| 235 | static int rfkill_suspend(struct device *dev, pm_message_t state) |
| 236 | { |
| 237 | struct rfkill *rfkill = to_rfkill(dev); |
| 238 | |
| 239 | if (dev->power.power_state.event != state.event) { |
Rafael J. Wysocki | 3a2d5b7 | 2008-02-23 19:13:25 +0100 | [diff] [blame] | 240 | if (state.event & PM_EVENT_SLEEP) { |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 241 | mutex_lock(&rfkill->mutex); |
| 242 | |
| 243 | if (rfkill->state == RFKILL_STATE_ON) |
| 244 | rfkill->toggle_radio(rfkill->data, |
| 245 | RFKILL_STATE_OFF); |
| 246 | |
| 247 | mutex_unlock(&rfkill->mutex); |
| 248 | } |
| 249 | |
| 250 | dev->power.power_state = state; |
| 251 | } |
| 252 | |
| 253 | return 0; |
| 254 | } |
| 255 | |
| 256 | static int rfkill_resume(struct device *dev) |
| 257 | { |
| 258 | struct rfkill *rfkill = to_rfkill(dev); |
| 259 | |
| 260 | if (dev->power.power_state.event != PM_EVENT_ON) { |
| 261 | mutex_lock(&rfkill->mutex); |
| 262 | |
| 263 | if (rfkill->state == RFKILL_STATE_ON) |
| 264 | rfkill->toggle_radio(rfkill->data, RFKILL_STATE_ON); |
| 265 | |
| 266 | mutex_unlock(&rfkill->mutex); |
| 267 | } |
| 268 | |
| 269 | dev->power.power_state = PMSG_ON; |
| 270 | return 0; |
| 271 | } |
| 272 | #else |
| 273 | #define rfkill_suspend NULL |
| 274 | #define rfkill_resume NULL |
| 275 | #endif |
| 276 | |
| 277 | static struct class rfkill_class = { |
| 278 | .name = "rfkill", |
| 279 | .dev_release = rfkill_release, |
| 280 | .dev_attrs = rfkill_dev_attrs, |
| 281 | .suspend = rfkill_suspend, |
| 282 | .resume = rfkill_resume, |
| 283 | }; |
| 284 | |
| 285 | static int rfkill_add_switch(struct rfkill *rfkill) |
| 286 | { |
Michael Buesch | 7319f1e | 2007-10-28 15:16:50 +0100 | [diff] [blame] | 287 | int error; |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 288 | |
Michael Buesch | 7319f1e | 2007-10-28 15:16:50 +0100 | [diff] [blame] | 289 | mutex_lock(&rfkill_mutex); |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 290 | |
Michael Buesch | 7319f1e | 2007-10-28 15:16:50 +0100 | [diff] [blame] | 291 | error = rfkill_toggle_radio(rfkill, rfkill_states[rfkill->type]); |
| 292 | if (!error) |
| 293 | list_add_tail(&rfkill->node, &rfkill_list); |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 294 | |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 295 | mutex_unlock(&rfkill_mutex); |
Michael Buesch | 7319f1e | 2007-10-28 15:16:50 +0100 | [diff] [blame] | 296 | |
| 297 | return error; |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | static void rfkill_remove_switch(struct rfkill *rfkill) |
| 301 | { |
| 302 | mutex_lock(&rfkill_mutex); |
| 303 | list_del_init(&rfkill->node); |
| 304 | rfkill_toggle_radio(rfkill, RFKILL_STATE_OFF); |
| 305 | mutex_unlock(&rfkill_mutex); |
| 306 | } |
| 307 | |
| 308 | /** |
| 309 | * rfkill_allocate - allocate memory for rfkill structure. |
| 310 | * @parent: device that has rf switch on it |
Ivo van Doorn | 234a0ca | 2007-09-13 09:20:42 +0200 | [diff] [blame] | 311 | * @type: type of the switch (RFKILL_TYPE_*) |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 312 | * |
| 313 | * This function should be called by the network driver when it needs |
| 314 | * rfkill structure. Once the structure is allocated the driver shoud |
| 315 | * finish its initialization by setting name, private data, enable_radio |
| 316 | * and disable_radio methods and then register it with rfkill_register(). |
| 317 | * NOTE: If registration fails the structure shoudl be freed by calling |
| 318 | * rfkill_free() otherwise rfkill_unregister() should be used. |
| 319 | */ |
| 320 | struct rfkill *rfkill_allocate(struct device *parent, enum rfkill_type type) |
| 321 | { |
| 322 | struct rfkill *rfkill; |
| 323 | struct device *dev; |
| 324 | |
| 325 | rfkill = kzalloc(sizeof(struct rfkill), GFP_KERNEL); |
Ivo van Doorn | d007da1 | 2007-05-19 12:24:39 -0700 | [diff] [blame] | 326 | if (!rfkill) |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 327 | return NULL; |
| 328 | |
| 329 | mutex_init(&rfkill->mutex); |
| 330 | INIT_LIST_HEAD(&rfkill->node); |
| 331 | rfkill->type = type; |
| 332 | |
| 333 | dev = &rfkill->dev; |
| 334 | dev->class = &rfkill_class; |
| 335 | dev->parent = parent; |
| 336 | device_initialize(dev); |
| 337 | |
| 338 | __module_get(THIS_MODULE); |
| 339 | |
| 340 | return rfkill; |
| 341 | } |
| 342 | EXPORT_SYMBOL(rfkill_allocate); |
| 343 | |
| 344 | /** |
| 345 | * rfkill_free - Mark rfkill structure for deletion |
| 346 | * @rfkill: rfkill structure to be destroyed |
| 347 | * |
Oliver Pinter | 1dbede8 | 2008-02-03 17:55:45 +0200 | [diff] [blame] | 348 | * Decrements reference count of rfkill structure so it is destroyed. |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 349 | * Note that rfkill_free() should _not_ be called after rfkill_unregister(). |
| 350 | */ |
| 351 | void rfkill_free(struct rfkill *rfkill) |
| 352 | { |
| 353 | if (rfkill) |
| 354 | put_device(&rfkill->dev); |
| 355 | } |
| 356 | EXPORT_SYMBOL(rfkill_free); |
| 357 | |
Michael Buesch | 135900c | 2007-09-27 21:33:12 +0200 | [diff] [blame] | 358 | static void rfkill_led_trigger_register(struct rfkill *rfkill) |
| 359 | { |
| 360 | #ifdef CONFIG_RFKILL_LEDS |
| 361 | int error; |
| 362 | |
| 363 | rfkill->led_trigger.name = rfkill->dev.bus_id; |
| 364 | error = led_trigger_register(&rfkill->led_trigger); |
| 365 | if (error) |
| 366 | rfkill->led_trigger.name = NULL; |
| 367 | #endif /* CONFIG_RFKILL_LEDS */ |
| 368 | } |
| 369 | |
| 370 | static void rfkill_led_trigger_unregister(struct rfkill *rfkill) |
| 371 | { |
| 372 | #ifdef CONFIG_RFKILL_LEDS |
| 373 | if (rfkill->led_trigger.name) |
| 374 | led_trigger_unregister(&rfkill->led_trigger); |
| 375 | #endif |
| 376 | } |
| 377 | |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 378 | /** |
| 379 | * rfkill_register - Register a rfkill structure. |
| 380 | * @rfkill: rfkill structure to be registered |
| 381 | * |
| 382 | * This function should be called by the network driver when the rfkill |
| 383 | * structure needs to be registered. Immediately from registration the |
| 384 | * switch driver should be able to service calls to toggle_radio. |
| 385 | */ |
| 386 | int rfkill_register(struct rfkill *rfkill) |
| 387 | { |
| 388 | static atomic_t rfkill_no = ATOMIC_INIT(0); |
| 389 | struct device *dev = &rfkill->dev; |
| 390 | int error; |
| 391 | |
| 392 | if (!rfkill->toggle_radio) |
| 393 | return -EINVAL; |
Michael Buesch | 7319f1e | 2007-10-28 15:16:50 +0100 | [diff] [blame] | 394 | if (rfkill->type >= RFKILL_TYPE_MAX) |
| 395 | return -EINVAL; |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 396 | |
Michael Buesch | 8a8f1c0 | 2007-10-28 13:07:54 +0100 | [diff] [blame] | 397 | snprintf(dev->bus_id, sizeof(dev->bus_id), |
| 398 | "rfkill%ld", (long)atomic_inc_return(&rfkill_no) - 1); |
| 399 | |
| 400 | rfkill_led_trigger_register(rfkill); |
| 401 | |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 402 | error = rfkill_add_switch(rfkill); |
Eric Paris | 632041f | 2008-01-13 16:20:56 -0500 | [diff] [blame] | 403 | if (error) { |
| 404 | rfkill_led_trigger_unregister(rfkill); |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 405 | return error; |
Eric Paris | 632041f | 2008-01-13 16:20:56 -0500 | [diff] [blame] | 406 | } |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 407 | |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 408 | error = device_add(dev); |
| 409 | if (error) { |
Eric Paris | 632041f | 2008-01-13 16:20:56 -0500 | [diff] [blame] | 410 | rfkill_led_trigger_unregister(rfkill); |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 411 | rfkill_remove_switch(rfkill); |
| 412 | return error; |
| 413 | } |
| 414 | |
| 415 | return 0; |
| 416 | } |
| 417 | EXPORT_SYMBOL(rfkill_register); |
| 418 | |
| 419 | /** |
Henrique de Moraes Holschuh | c8fcd90 | 2008-06-23 17:22:57 -0300 | [diff] [blame] | 420 | * rfkill_unregister - Unregister a rfkill structure. |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 421 | * @rfkill: rfkill structure to be unregistered |
| 422 | * |
| 423 | * This function should be called by the network driver during device |
| 424 | * teardown to destroy rfkill structure. Note that rfkill_free() should |
| 425 | * _not_ be called after rfkill_unregister(). |
| 426 | */ |
| 427 | void rfkill_unregister(struct rfkill *rfkill) |
| 428 | { |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 429 | device_del(&rfkill->dev); |
| 430 | rfkill_remove_switch(rfkill); |
Michael Buesch | 8a8f1c0 | 2007-10-28 13:07:54 +0100 | [diff] [blame] | 431 | rfkill_led_trigger_unregister(rfkill); |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 432 | put_device(&rfkill->dev); |
| 433 | } |
| 434 | EXPORT_SYMBOL(rfkill_unregister); |
| 435 | |
| 436 | /* |
| 437 | * Rfkill module initialization/deinitialization. |
| 438 | */ |
| 439 | static int __init rfkill_init(void) |
| 440 | { |
| 441 | int error; |
| 442 | int i; |
| 443 | |
Henrique de Moraes Holschuh | e954b0b | 2008-06-23 17:22:59 -0300 | [diff] [blame^] | 444 | if (rfkill_default_state != RFKILL_STATE_OFF && |
| 445 | rfkill_default_state != RFKILL_STATE_ON) |
| 446 | return -EINVAL; |
| 447 | |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 448 | for (i = 0; i < ARRAY_SIZE(rfkill_states); i++) |
Henrique de Moraes Holschuh | e954b0b | 2008-06-23 17:22:59 -0300 | [diff] [blame^] | 449 | rfkill_states[i] = rfkill_default_state; |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 450 | |
| 451 | error = class_register(&rfkill_class); |
| 452 | if (error) { |
| 453 | printk(KERN_ERR "rfkill: unable to register rfkill class\n"); |
| 454 | return error; |
| 455 | } |
| 456 | |
| 457 | return 0; |
| 458 | } |
| 459 | |
| 460 | static void __exit rfkill_exit(void) |
| 461 | { |
| 462 | class_unregister(&rfkill_class); |
| 463 | } |
| 464 | |
Michael Buesch | 2bf236d | 2007-10-28 14:39:02 +0100 | [diff] [blame] | 465 | subsys_initcall(rfkill_init); |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 466 | module_exit(rfkill_exit); |