rfkill.c 18.7 KB
Newer Older
1
/*
2
 * Copyright (C) 2006 - 2007 Ivo van Doorn
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
 * Copyright (C) 2007 Dmitry Torokhov
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the
 * Free Software Foundation, Inc.,
 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/workqueue.h>
#include <linux/capability.h>
#include <linux/list.h>
#include <linux/mutex.h>
#include <linux/rfkill.h>

30 31 32 33
/* Get declaration of rfkill_switch_all() to shut up sparse. */
#include "rfkill-input.h"


34 35 36 37 38 39 40 41
MODULE_AUTHOR("Ivo van Doorn <IvDoorn@gmail.com>");
MODULE_VERSION("1.0");
MODULE_DESCRIPTION("RF switch support");
MODULE_LICENSE("GPL");

static LIST_HEAD(rfkill_list);	/* list of registered rf switches */
static DEFINE_MUTEX(rfkill_mutex);

42
static unsigned int rfkill_default_state = RFKILL_STATE_UNBLOCKED;
43 44 45 46
module_param_named(default_state, rfkill_default_state, uint, 0444);
MODULE_PARM_DESC(default_state,
		 "Default initial state for all radio types, 0 = radio off");

47 48
static enum rfkill_state rfkill_states[RFKILL_TYPE_MAX];

49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
static BLOCKING_NOTIFIER_HEAD(rfkill_notifier_list);


/**
 * register_rfkill_notifier - Add notifier to rfkill notifier chain
 * @nb: pointer to the new entry to add to the chain
 *
 * See blocking_notifier_chain_register() for return value and further
 * observations.
 *
 * Adds a notifier to the rfkill notifier chain.  The chain will be
 * called with a pointer to the relevant rfkill structure as a parameter,
 * refer to include/linux/rfkill.h for the possible events.
 *
 * Notifiers added to this chain are to always return NOTIFY_DONE.  This
 * chain is a blocking notifier chain: notifiers can sleep.
 *
 * Calls to this chain may have been done through a workqueue.  One must
 * assume unordered asynchronous behaviour, there is no way to know if
 * actions related to the event that generated the notification have been
 * carried out already.
 */
int register_rfkill_notifier(struct notifier_block *nb)
{
	return blocking_notifier_chain_register(&rfkill_notifier_list, nb);
}
EXPORT_SYMBOL_GPL(register_rfkill_notifier);

/**
 * unregister_rfkill_notifier - remove notifier from rfkill notifier chain
 * @nb: pointer to the entry to remove from the chain
 *
 * See blocking_notifier_chain_unregister() for return value and further
 * observations.
 *
 * Removes a notifier from the rfkill notifier chain.
 */
int unregister_rfkill_notifier(struct notifier_block *nb)
{
	return blocking_notifier_chain_unregister(&rfkill_notifier_list, nb);
}
EXPORT_SYMBOL_GPL(unregister_rfkill_notifier);

92 93 94 95 96 97 98 99 100

static void rfkill_led_trigger(struct rfkill *rfkill,
			       enum rfkill_state state)
{
#ifdef CONFIG_RFKILL_LEDS
	struct led_trigger *led = &rfkill->led_trigger;

	if (!led->name)
		return;
101
	if (state != RFKILL_STATE_UNBLOCKED)
102 103 104 105 106 107
		led_trigger_event(led, LED_OFF);
	else
		led_trigger_event(led, LED_FULL);
#endif /* CONFIG_RFKILL_LEDS */
}

108 109 110 111 112 113 114 115 116 117
#ifdef CONFIG_RFKILL_LEDS
static void rfkill_led_trigger_activate(struct led_classdev *led)
{
	struct rfkill *rfkill = container_of(led->trigger,
			struct rfkill, led_trigger);

	rfkill_led_trigger(rfkill, rfkill->state);
}
#endif /* CONFIG_RFKILL_LEDS */

118 119 120 121 122 123 124
static void notify_rfkill_state_change(struct rfkill *rfkill)
{
	blocking_notifier_call_chain(&rfkill_notifier_list,
			RFKILL_STATE_CHANGED,
			rfkill);
}

125 126
static void update_rfkill_state(struct rfkill *rfkill)
{
127
	enum rfkill_state newstate, oldstate;
128 129 130

	if (rfkill->get_state) {
		mutex_lock(&rfkill->mutex);
131 132
		if (!rfkill->get_state(rfkill->data, &newstate)) {
			oldstate = rfkill->state;
133
			rfkill->state = newstate;
134 135 136
			if (oldstate != newstate)
				notify_rfkill_state_change(rfkill);
		}
137 138 139 140
		mutex_unlock(&rfkill->mutex);
	}
}

141 142 143 144 145 146 147 148
/**
 * rfkill_toggle_radio - wrapper for toggle_radio hook
 * @rfkill: the rfkill struct to use
 * @force: calls toggle_radio even if cache says it is not needed,
 *	and also makes sure notifications of the state will be
 *	sent even if it didn't change
 * @state: the new state to call toggle_radio() with
 *
149 150 151 152
 * Calls rfkill->toggle_radio, enforcing the API for toggle_radio
 * calls and handling all the red tape such as issuing notifications
 * if the call is successful.
 *
153 154
 * Suspended devices are not touched at all, and -EAGAIN is returned.
 *
155 156
 * Note that the @force parameter cannot override a (possibly cached)
 * state of RFKILL_STATE_HARD_BLOCKED.  Any device making use of
157 158 159 160 161 162 163
 * RFKILL_STATE_HARD_BLOCKED implements either get_state() or
 * rfkill_force_state(), so the cache either is bypassed or valid.
 *
 * Note that we do call toggle_radio for RFKILL_STATE_SOFT_BLOCKED
 * even if the radio is in RFKILL_STATE_HARD_BLOCKED state, so as to
 * give the driver a hint that it should double-BLOCK the transmitter.
 *
164
 * Caller must have acquired rfkill->mutex.
165
 */
166
static int rfkill_toggle_radio(struct rfkill *rfkill,
167 168
				enum rfkill_state state,
				int force)
169
{
170
	int retval = 0;
171 172
	enum rfkill_state oldstate, newstate;

173 174 175
	if (unlikely(rfkill->dev.power.power_state.event & PM_EVENT_SLEEP))
		return -EBUSY;

176 177
	oldstate = rfkill->state;

178
	if (rfkill->get_state && !force &&
179 180
	    !rfkill->get_state(rfkill->data, &newstate))
		rfkill->state = newstate;
181

182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
	switch (state) {
	case RFKILL_STATE_HARD_BLOCKED:
		/* typically happens when refreshing hardware state,
		 * such as on resume */
		state = RFKILL_STATE_SOFT_BLOCKED;
		break;
	case RFKILL_STATE_UNBLOCKED:
		/* force can't override this, only rfkill_force_state() can */
		if (rfkill->state == RFKILL_STATE_HARD_BLOCKED)
			return -EPERM;
		break;
	case RFKILL_STATE_SOFT_BLOCKED:
		/* nothing to do, we want to give drivers the hint to double
		 * BLOCK even a transmitter that is already in state
		 * RFKILL_STATE_HARD_BLOCKED */
		break;
	}

200
	if (force || state != rfkill->state) {
201
		retval = rfkill->toggle_radio(rfkill->data, state);
202 203
		/* never allow a HARD->SOFT downgrade! */
		if (!retval && rfkill->state != RFKILL_STATE_HARD_BLOCKED)
204 205 206
			rfkill->state = state;
	}

207
	if (force || rfkill->state != oldstate) {
208
		rfkill_led_trigger(rfkill, rfkill->state);
209 210
		notify_rfkill_state_change(rfkill);
	}
211

212 213 214 215 216
	return retval;
}

/**
 * rfkill_switch_all - Toggle state of all switches of given type
217
 * @type: type of interfaces to be affected
218 219
 * @state: the new state
 *
220 221
 * This function toggles the state of all switches of given type,
 * unless a specific switch is claimed by userspace (in which case,
222
 * that switch is left alone) or suspended.
223 224 225 226 227 228 229 230 231 232
 */
void rfkill_switch_all(enum rfkill_type type, enum rfkill_state state)
{
	struct rfkill *rfkill;

	mutex_lock(&rfkill_mutex);

	rfkill_states[type] = state;

	list_for_each_entry(rfkill, &rfkill_list, node) {
233 234
		if ((!rfkill->user_claim) && (rfkill->type == type)) {
			mutex_lock(&rfkill->mutex);
235
			rfkill_toggle_radio(rfkill, state, 0);
236 237
			mutex_unlock(&rfkill->mutex);
		}
238 239 240 241 242 243
	}

	mutex_unlock(&rfkill_mutex);
}
EXPORT_SYMBOL(rfkill_switch_all);

244 245 246
/**
 * rfkill_epo - emergency power off all transmitters
 *
247 248
 * This kicks all non-suspended rfkill devices to RFKILL_STATE_SOFT_BLOCKED,
 * ignoring everything in its path but rfkill_mutex and rfkill->mutex.
249 250 251 252 253 254 255
 */
void rfkill_epo(void)
{
	struct rfkill *rfkill;

	mutex_lock(&rfkill_mutex);
	list_for_each_entry(rfkill, &rfkill_list, node) {
256
		mutex_lock(&rfkill->mutex);
257
		rfkill_toggle_radio(rfkill, RFKILL_STATE_SOFT_BLOCKED, 1);
258
		mutex_unlock(&rfkill->mutex);
259 260 261 262 263
	}
	mutex_unlock(&rfkill_mutex);
}
EXPORT_SYMBOL_GPL(rfkill_epo);

264 265 266 267 268 269 270 271 272 273
/**
 * rfkill_force_state - Force the internal rfkill radio state
 * @rfkill: pointer to the rfkill class to modify.
 * @state: the current radio state the class should be forced to.
 *
 * This function updates the internal state of the radio cached
 * by the rfkill class.  It should be used when the driver gets
 * a notification by the firmware/hardware of the current *real*
 * state of the radio rfkill switch.
 *
274 275 276 277 278 279
 * Devices which are subject to external changes on their rfkill
 * state (such as those caused by a hardware rfkill line) MUST
 * have their driver arrange to call rfkill_force_state() as soon
 * as possible after such a change.
 *
 * This function may not be called from an atomic context.
280 281 282
 */
int rfkill_force_state(struct rfkill *rfkill, enum rfkill_state state)
{
283 284
	enum rfkill_state oldstate;

285 286 287
	if (state != RFKILL_STATE_SOFT_BLOCKED &&
	    state != RFKILL_STATE_UNBLOCKED &&
	    state != RFKILL_STATE_HARD_BLOCKED)
288 289 290
		return -EINVAL;

	mutex_lock(&rfkill->mutex);
291 292

	oldstate = rfkill->state;
293
	rfkill->state = state;
294 295 296 297

	if (state != oldstate)
		notify_rfkill_state_change(rfkill);

298 299 300 301 302 303
	mutex_unlock(&rfkill->mutex);

	return 0;
}
EXPORT_SYMBOL(rfkill_force_state);

304 305 306 307 308 309 310 311 312
static ssize_t rfkill_name_show(struct device *dev,
				struct device_attribute *attr,
				char *buf)
{
	struct rfkill *rfkill = to_rfkill(dev);

	return sprintf(buf, "%s\n", rfkill->name);
}

313
static const char *rfkill_get_type_str(enum rfkill_type type)
314
{
315
	switch (type) {
316
	case RFKILL_TYPE_WLAN:
317
		return "wlan";
318
	case RFKILL_TYPE_BLUETOOTH:
319
		return "bluetooth";
320
	case RFKILL_TYPE_UWB:
321
		return "ultrawideband";
322
	case RFKILL_TYPE_WIMAX:
323
		return "wimax";
324
	case RFKILL_TYPE_WWAN:
325
		return "wwan";
326 327 328
	default:
		BUG();
	}
329 330 331 332 333 334 335
}

static ssize_t rfkill_type_show(struct device *dev,
				struct device_attribute *attr,
				char *buf)
{
	struct rfkill *rfkill = to_rfkill(dev);
336

337
	return sprintf(buf, "%s\n", rfkill_get_type_str(rfkill->type));
338 339 340 341 342 343 344 345
}

static ssize_t rfkill_state_show(struct device *dev,
				 struct device_attribute *attr,
				 char *buf)
{
	struct rfkill *rfkill = to_rfkill(dev);

346
	update_rfkill_state(rfkill);
347 348 349 350 351 352 353 354 355 356 357 358 359 360
	return sprintf(buf, "%d\n", rfkill->state);
}

static ssize_t rfkill_state_store(struct device *dev,
				  struct device_attribute *attr,
				  const char *buf, size_t count)
{
	struct rfkill *rfkill = to_rfkill(dev);
	unsigned int state = simple_strtoul(buf, NULL, 0);
	int error;

	if (!capable(CAP_NET_ADMIN))
		return -EPERM;

361 362 363 364 365
	/* RFKILL_STATE_HARD_BLOCKED is illegal here... */
	if (state != RFKILL_STATE_UNBLOCKED &&
	    state != RFKILL_STATE_SOFT_BLOCKED)
		return -EINVAL;

366 367
	if (mutex_lock_interruptible(&rfkill->mutex))
		return -ERESTARTSYS;
368
	error = rfkill_toggle_radio(rfkill, state, 0);
369
	mutex_unlock(&rfkill->mutex);
370

371
	return error ? error : count;
372 373 374 375 376 377 378 379
}

static ssize_t rfkill_claim_show(struct device *dev,
				 struct device_attribute *attr,
				 char *buf)
{
	struct rfkill *rfkill = to_rfkill(dev);

380
	return sprintf(buf, "%d\n", rfkill->user_claim);
381 382 383 384 385 386 387 388 389 390 391 392 393
}

static ssize_t rfkill_claim_store(struct device *dev,
				  struct device_attribute *attr,
				  const char *buf, size_t count)
{
	struct rfkill *rfkill = to_rfkill(dev);
	bool claim = !!simple_strtoul(buf, NULL, 0);
	int error;

	if (!capable(CAP_NET_ADMIN))
		return -EPERM;

394 395 396
	if (rfkill->user_claim_unsupported)
		return -EOPNOTSUPP;

397 398 399 400 401 402 403 404 405
	/*
	 * Take the global lock to make sure the kernel is not in
	 * the middle of rfkill_switch_all
	 */
	error = mutex_lock_interruptible(&rfkill_mutex);
	if (error)
		return error;

	if (rfkill->user_claim != claim) {
406 407
		if (!claim) {
			mutex_lock(&rfkill->mutex);
408
			rfkill_toggle_radio(rfkill,
409 410
					    rfkill_states[rfkill->type],
					    0);
411 412
			mutex_unlock(&rfkill->mutex);
		}
413 414 415 416 417
		rfkill->user_claim = claim;
	}

	mutex_unlock(&rfkill_mutex);

418
	return error ? error : count;
419 420 421 422 423
}

static struct device_attribute rfkill_dev_attrs[] = {
	__ATTR(name, S_IRUGO, rfkill_name_show, NULL),
	__ATTR(type, S_IRUGO, rfkill_type_show, NULL),
424
	__ATTR(state, S_IRUGO|S_IWUSR, rfkill_state_show, rfkill_state_store),
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442
	__ATTR(claim, S_IRUGO|S_IWUSR, rfkill_claim_show, rfkill_claim_store),
	__ATTR_NULL
};

static void rfkill_release(struct device *dev)
{
	struct rfkill *rfkill = to_rfkill(dev);

	kfree(rfkill);
	module_put(THIS_MODULE);
}

#ifdef CONFIG_PM
static int rfkill_suspend(struct device *dev, pm_message_t state)
{
	struct rfkill *rfkill = to_rfkill(dev);

	if (dev->power.power_state.event != state.event) {
443
		if (state.event & PM_EVENT_SLEEP) {
444 445
			/* Stop transmitter, keep state, no notifies */
			update_rfkill_state(rfkill);
446

447
			mutex_lock(&rfkill->mutex);
448 449
			rfkill->toggle_radio(rfkill->data,
						RFKILL_STATE_SOFT_BLOCKED);
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465
			mutex_unlock(&rfkill->mutex);
		}

		dev->power.power_state = state;
	}

	return 0;
}

static int rfkill_resume(struct device *dev)
{
	struct rfkill *rfkill = to_rfkill(dev);

	if (dev->power.power_state.event != PM_EVENT_ON) {
		mutex_lock(&rfkill->mutex);

466 467
		dev->power.power_state.event = PM_EVENT_ON;

468 469
		/* restore radio state AND notify everybody */
		rfkill_toggle_radio(rfkill, rfkill->state, 1);
470 471 472 473 474 475 476 477 478 479 480

		mutex_unlock(&rfkill->mutex);
	}

	return 0;
}
#else
#define rfkill_suspend NULL
#define rfkill_resume NULL
#endif

481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518
static int rfkill_blocking_uevent_notifier(struct notifier_block *nb,
					unsigned long eventid,
					void *data)
{
	struct rfkill *rfkill = (struct rfkill *)data;

	switch (eventid) {
	case RFKILL_STATE_CHANGED:
		kobject_uevent(&rfkill->dev.kobj, KOBJ_CHANGE);
		break;
	default:
		break;
	}

	return NOTIFY_DONE;
}

static struct notifier_block rfkill_blocking_uevent_nb = {
	.notifier_call	= rfkill_blocking_uevent_notifier,
	.priority	= 0,
};

static int rfkill_dev_uevent(struct device *dev, struct kobj_uevent_env *env)
{
	struct rfkill *rfkill = to_rfkill(dev);
	int error;

	error = add_uevent_var(env, "RFKILL_NAME=%s", rfkill->name);
	if (error)
		return error;
	error = add_uevent_var(env, "RFKILL_TYPE=%s",
				rfkill_get_type_str(rfkill->type));
	if (error)
		return error;
	error = add_uevent_var(env, "RFKILL_STATE=%d", rfkill->state);
	return error;
}

519 520 521 522 523 524
static struct class rfkill_class = {
	.name		= "rfkill",
	.dev_release	= rfkill_release,
	.dev_attrs	= rfkill_dev_attrs,
	.suspend	= rfkill_suspend,
	.resume		= rfkill_resume,
525
	.dev_uevent	= rfkill_dev_uevent,
526 527 528 529
};

static int rfkill_add_switch(struct rfkill *rfkill)
{
530
	mutex_lock(&rfkill_mutex);
531

532 533 534
	rfkill_toggle_radio(rfkill, rfkill_states[rfkill->type], 0);

	list_add_tail(&rfkill->node, &rfkill_list);
535 536

	mutex_unlock(&rfkill_mutex);
537

538
	return 0;
539 540 541 542 543 544 545
}

static void rfkill_remove_switch(struct rfkill *rfkill)
{
	mutex_lock(&rfkill_mutex);
	list_del_init(&rfkill->node);
	mutex_unlock(&rfkill_mutex);
546 547 548 549

	mutex_lock(&rfkill->mutex);
	rfkill_toggle_radio(rfkill, RFKILL_STATE_SOFT_BLOCKED, 1);
	mutex_unlock(&rfkill->mutex);
550 551 552 553 554
}

/**
 * rfkill_allocate - allocate memory for rfkill structure.
 * @parent: device that has rf switch on it
I
Ivo van Doorn 已提交
555
 * @type: type of the switch (RFKILL_TYPE_*)
556 557
 *
 * This function should be called by the network driver when it needs
558 559
 * rfkill structure.  Once the structure is allocated the driver should
 * finish its initialization by setting the name, private data, enable_radio
560
 * and disable_radio methods and then register it with rfkill_register().
561
 *
562 563 564 565 566 567 568 569 570
 * NOTE: If registration fails the structure shoudl be freed by calling
 * rfkill_free() otherwise rfkill_unregister() should be used.
 */
struct rfkill *rfkill_allocate(struct device *parent, enum rfkill_type type)
{
	struct rfkill *rfkill;
	struct device *dev;

	rfkill = kzalloc(sizeof(struct rfkill), GFP_KERNEL);
571
	if (!rfkill)
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592
		return NULL;

	mutex_init(&rfkill->mutex);
	INIT_LIST_HEAD(&rfkill->node);
	rfkill->type = type;

	dev = &rfkill->dev;
	dev->class = &rfkill_class;
	dev->parent = parent;
	device_initialize(dev);

	__module_get(THIS_MODULE);

	return rfkill;
}
EXPORT_SYMBOL(rfkill_allocate);

/**
 * rfkill_free - Mark rfkill structure for deletion
 * @rfkill: rfkill structure to be destroyed
 *
593
 * Decrements reference count of the rfkill structure so it is destroyed.
594 595 596 597 598 599 600 601 602
 * Note that rfkill_free() should _not_ be called after rfkill_unregister().
 */
void rfkill_free(struct rfkill *rfkill)
{
	if (rfkill)
		put_device(&rfkill->dev);
}
EXPORT_SYMBOL(rfkill_free);

603 604 605 606 607
static void rfkill_led_trigger_register(struct rfkill *rfkill)
{
#ifdef CONFIG_RFKILL_LEDS
	int error;

608 609
	if (!rfkill->led_trigger.name)
		rfkill->led_trigger.name = rfkill->dev.bus_id;
610 611
	if (!rfkill->led_trigger.activate)
		rfkill->led_trigger.activate = rfkill_led_trigger_activate;
612 613 614 615 616 617 618 619 620
	error = led_trigger_register(&rfkill->led_trigger);
	if (error)
		rfkill->led_trigger.name = NULL;
#endif /* CONFIG_RFKILL_LEDS */
}

static void rfkill_led_trigger_unregister(struct rfkill *rfkill)
{
#ifdef CONFIG_RFKILL_LEDS
621
	if (rfkill->led_trigger.name) {
622
		led_trigger_unregister(&rfkill->led_trigger);
623 624
		rfkill->led_trigger.name = NULL;
	}
625 626 627
#endif
}

628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643
/**
 * rfkill_register - Register a rfkill structure.
 * @rfkill: rfkill structure to be registered
 *
 * This function should be called by the network driver when the rfkill
 * structure needs to be registered. Immediately from registration the
 * switch driver should be able to service calls to toggle_radio.
 */
int rfkill_register(struct rfkill *rfkill)
{
	static atomic_t rfkill_no = ATOMIC_INIT(0);
	struct device *dev = &rfkill->dev;
	int error;

	if (!rfkill->toggle_radio)
		return -EINVAL;
644 645
	if (rfkill->type >= RFKILL_TYPE_MAX)
		return -EINVAL;
646

647 648 649 650 651
	snprintf(dev->bus_id, sizeof(dev->bus_id),
		 "rfkill%ld", (long)atomic_inc_return(&rfkill_no) - 1);

	rfkill_led_trigger_register(rfkill);

652
	error = rfkill_add_switch(rfkill);
653 654
	if (error) {
		rfkill_led_trigger_unregister(rfkill);
655
		return error;
656
	}
657 658 659 660

	error = device_add(dev);
	if (error) {
		rfkill_remove_switch(rfkill);
661
		rfkill_led_trigger_unregister(rfkill);
662 663 664 665 666 667 668 669
		return error;
	}

	return 0;
}
EXPORT_SYMBOL(rfkill_register);

/**
670
 * rfkill_unregister - Unregister a rfkill structure.
671 672 673 674 675 676 677 678 679 680
 * @rfkill: rfkill structure to be unregistered
 *
 * This function should be called by the network driver during device
 * teardown to destroy rfkill structure. Note that rfkill_free() should
 * _not_ be called after rfkill_unregister().
 */
void rfkill_unregister(struct rfkill *rfkill)
{
	device_del(&rfkill->dev);
	rfkill_remove_switch(rfkill);
681
	rfkill_led_trigger_unregister(rfkill);
682 683 684 685 686 687 688 689 690 691 692 693
	put_device(&rfkill->dev);
}
EXPORT_SYMBOL(rfkill_unregister);

/*
 * Rfkill module initialization/deinitialization.
 */
static int __init rfkill_init(void)
{
	int error;
	int i;

694 695 696
	/* RFKILL_STATE_HARD_BLOCKED is illegal here... */
	if (rfkill_default_state != RFKILL_STATE_SOFT_BLOCKED &&
	    rfkill_default_state != RFKILL_STATE_UNBLOCKED)
697 698
		return -EINVAL;

699
	for (i = 0; i < ARRAY_SIZE(rfkill_states); i++)
700
		rfkill_states[i] = rfkill_default_state;
701 702 703 704 705 706 707

	error = class_register(&rfkill_class);
	if (error) {
		printk(KERN_ERR "rfkill: unable to register rfkill class\n");
		return error;
	}

708 709
	register_rfkill_notifier(&rfkill_blocking_uevent_nb);

710 711 712 713 714
	return 0;
}

static void __exit rfkill_exit(void)
{
715
	unregister_rfkill_notifier(&rfkill_blocking_uevent_nb);
716 717 718
	class_unregister(&rfkill_class);
}

719
subsys_initcall(rfkill_init);
720
module_exit(rfkill_exit);
新手
引导
客服 返回
顶部