rfkill.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. /*
  2. * Copyright (C) 2006 - 2007 Ivo van Doorn
  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. #include <linux/kernel.h>
  21. #include <linux/module.h>
  22. #include <linux/init.h>
  23. #include <linux/workqueue.h>
  24. #include <linux/capability.h>
  25. #include <linux/list.h>
  26. #include <linux/mutex.h>
  27. #include <linux/rfkill.h>
  28. /* Get declaration of rfkill_switch_all() to shut up sparse. */
  29. #include "rfkill-input.h"
  30. MODULE_AUTHOR("Ivo van Doorn <IvDoorn@gmail.com>");
  31. MODULE_VERSION("1.0");
  32. MODULE_DESCRIPTION("RF switch support");
  33. MODULE_LICENSE("GPL");
  34. static LIST_HEAD(rfkill_list); /* list of registered rf switches */
  35. static DEFINE_MUTEX(rfkill_mutex);
  36. static unsigned int rfkill_default_state = RFKILL_STATE_UNBLOCKED;
  37. module_param_named(default_state, rfkill_default_state, uint, 0444);
  38. MODULE_PARM_DESC(default_state,
  39. "Default initial state for all radio types, 0 = radio off");
  40. static enum rfkill_state rfkill_states[RFKILL_TYPE_MAX];
  41. static BLOCKING_NOTIFIER_HEAD(rfkill_notifier_list);
  42. /**
  43. * register_rfkill_notifier - Add notifier to rfkill notifier chain
  44. * @nb: pointer to the new entry to add to the chain
  45. *
  46. * See blocking_notifier_chain_register() for return value and further
  47. * observations.
  48. *
  49. * Adds a notifier to the rfkill notifier chain. The chain will be
  50. * called with a pointer to the relevant rfkill structure as a parameter,
  51. * refer to include/linux/rfkill.h for the possible events.
  52. *
  53. * Notifiers added to this chain are to always return NOTIFY_DONE. This
  54. * chain is a blocking notifier chain: notifiers can sleep.
  55. *
  56. * Calls to this chain may have been done through a workqueue. One must
  57. * assume unordered asynchronous behaviour, there is no way to know if
  58. * actions related to the event that generated the notification have been
  59. * carried out already.
  60. */
  61. int register_rfkill_notifier(struct notifier_block *nb)
  62. {
  63. return blocking_notifier_chain_register(&rfkill_notifier_list, nb);
  64. }
  65. EXPORT_SYMBOL_GPL(register_rfkill_notifier);
  66. /**
  67. * unregister_rfkill_notifier - remove notifier from rfkill notifier chain
  68. * @nb: pointer to the entry to remove from the chain
  69. *
  70. * See blocking_notifier_chain_unregister() for return value and further
  71. * observations.
  72. *
  73. * Removes a notifier from the rfkill notifier chain.
  74. */
  75. int unregister_rfkill_notifier(struct notifier_block *nb)
  76. {
  77. return blocking_notifier_chain_unregister(&rfkill_notifier_list, nb);
  78. }
  79. EXPORT_SYMBOL_GPL(unregister_rfkill_notifier);
  80. static void rfkill_led_trigger(struct rfkill *rfkill,
  81. enum rfkill_state state)
  82. {
  83. #ifdef CONFIG_RFKILL_LEDS
  84. struct led_trigger *led = &rfkill->led_trigger;
  85. if (!led->name)
  86. return;
  87. if (state != RFKILL_STATE_UNBLOCKED)
  88. led_trigger_event(led, LED_OFF);
  89. else
  90. led_trigger_event(led, LED_FULL);
  91. #endif /* CONFIG_RFKILL_LEDS */
  92. }
  93. static void notify_rfkill_state_change(struct rfkill *rfkill)
  94. {
  95. blocking_notifier_call_chain(&rfkill_notifier_list,
  96. RFKILL_STATE_CHANGED,
  97. rfkill);
  98. }
  99. static void update_rfkill_state(struct rfkill *rfkill)
  100. {
  101. enum rfkill_state newstate, oldstate;
  102. if (rfkill->get_state) {
  103. mutex_lock(&rfkill->mutex);
  104. if (!rfkill->get_state(rfkill->data, &newstate)) {
  105. oldstate = rfkill->state;
  106. rfkill->state = newstate;
  107. if (oldstate != newstate)
  108. notify_rfkill_state_change(rfkill);
  109. }
  110. mutex_unlock(&rfkill->mutex);
  111. }
  112. }
  113. /**
  114. * rfkill_toggle_radio - wrapper for toggle_radio hook
  115. *
  116. * @rfkill: the rfkill struct to use
  117. * @force: calls toggle_radio even if cache says it is not needed,
  118. * and also makes sure notifications of the state will be
  119. * sent even if it didn't change
  120. * @state: the new state to call toggle_radio() with
  121. *
  122. * Calls rfkill->toggle_radio, enforcing the API for toggle_radio
  123. * calls and handling all the red tape such as issuing notifications
  124. * if the call is successful.
  125. *
  126. * Note that @force cannot override a (possibly cached) state of
  127. * RFKILL_STATE_HARD_BLOCKED. Any device making use of
  128. * RFKILL_STATE_HARD_BLOCKED implements either get_state() or
  129. * rfkill_force_state(), so the cache either is bypassed or valid.
  130. *
  131. * Note that we do call toggle_radio for RFKILL_STATE_SOFT_BLOCKED
  132. * even if the radio is in RFKILL_STATE_HARD_BLOCKED state, so as to
  133. * give the driver a hint that it should double-BLOCK the transmitter.
  134. *
  135. * Caller must have aquired rfkill_mutex.
  136. */
  137. static int rfkill_toggle_radio(struct rfkill *rfkill,
  138. enum rfkill_state state,
  139. int force)
  140. {
  141. int retval = 0;
  142. enum rfkill_state oldstate, newstate;
  143. oldstate = rfkill->state;
  144. if (rfkill->get_state && !force &&
  145. !rfkill->get_state(rfkill->data, &newstate))
  146. rfkill->state = newstate;
  147. switch (state) {
  148. case RFKILL_STATE_HARD_BLOCKED:
  149. /* typically happens when refreshing hardware state,
  150. * such as on resume */
  151. state = RFKILL_STATE_SOFT_BLOCKED;
  152. break;
  153. case RFKILL_STATE_UNBLOCKED:
  154. /* force can't override this, only rfkill_force_state() can */
  155. if (rfkill->state == RFKILL_STATE_HARD_BLOCKED)
  156. return -EPERM;
  157. break;
  158. case RFKILL_STATE_SOFT_BLOCKED:
  159. /* nothing to do, we want to give drivers the hint to double
  160. * BLOCK even a transmitter that is already in state
  161. * RFKILL_STATE_HARD_BLOCKED */
  162. break;
  163. }
  164. if (force || state != rfkill->state) {
  165. retval = rfkill->toggle_radio(rfkill->data, state);
  166. /* never allow a HARD->SOFT downgrade! */
  167. if (!retval && rfkill->state != RFKILL_STATE_HARD_BLOCKED)
  168. rfkill->state = state;
  169. }
  170. if (force || rfkill->state != oldstate) {
  171. rfkill_led_trigger(rfkill, rfkill->state);
  172. notify_rfkill_state_change(rfkill);
  173. }
  174. return retval;
  175. }
  176. /**
  177. * rfkill_switch_all - Toggle state of all switches of given type
  178. * @type: type of interfaces to be affeceted
  179. * @state: the new state
  180. *
  181. * This function toggles state of all switches of given type unless
  182. * a specific switch is claimed by userspace in which case it is
  183. * left alone.
  184. */
  185. void rfkill_switch_all(enum rfkill_type type, enum rfkill_state state)
  186. {
  187. struct rfkill *rfkill;
  188. mutex_lock(&rfkill_mutex);
  189. rfkill_states[type] = state;
  190. list_for_each_entry(rfkill, &rfkill_list, node) {
  191. if ((!rfkill->user_claim) && (rfkill->type == type))
  192. rfkill_toggle_radio(rfkill, state, 0);
  193. }
  194. mutex_unlock(&rfkill_mutex);
  195. }
  196. EXPORT_SYMBOL(rfkill_switch_all);
  197. /**
  198. * rfkill_epo - emergency power off all transmitters
  199. *
  200. * This kicks all rfkill devices to RFKILL_STATE_SOFT_BLOCKED, ignoring
  201. * everything in its path but rfkill_mutex.
  202. */
  203. void rfkill_epo(void)
  204. {
  205. struct rfkill *rfkill;
  206. mutex_lock(&rfkill_mutex);
  207. list_for_each_entry(rfkill, &rfkill_list, node) {
  208. rfkill_toggle_radio(rfkill, RFKILL_STATE_SOFT_BLOCKED, 1);
  209. }
  210. mutex_unlock(&rfkill_mutex);
  211. }
  212. EXPORT_SYMBOL_GPL(rfkill_epo);
  213. /**
  214. * rfkill_force_state - Force the internal rfkill radio state
  215. * @rfkill: pointer to the rfkill class to modify.
  216. * @state: the current radio state the class should be forced to.
  217. *
  218. * This function updates the internal state of the radio cached
  219. * by the rfkill class. It should be used when the driver gets
  220. * a notification by the firmware/hardware of the current *real*
  221. * state of the radio rfkill switch.
  222. *
  223. * It may not be called from an atomic context.
  224. */
  225. int rfkill_force_state(struct rfkill *rfkill, enum rfkill_state state)
  226. {
  227. enum rfkill_state oldstate;
  228. if (state != RFKILL_STATE_SOFT_BLOCKED &&
  229. state != RFKILL_STATE_UNBLOCKED &&
  230. state != RFKILL_STATE_HARD_BLOCKED)
  231. return -EINVAL;
  232. mutex_lock(&rfkill->mutex);
  233. oldstate = rfkill->state;
  234. rfkill->state = state;
  235. if (state != oldstate)
  236. notify_rfkill_state_change(rfkill);
  237. mutex_unlock(&rfkill->mutex);
  238. return 0;
  239. }
  240. EXPORT_SYMBOL(rfkill_force_state);
  241. static ssize_t rfkill_name_show(struct device *dev,
  242. struct device_attribute *attr,
  243. char *buf)
  244. {
  245. struct rfkill *rfkill = to_rfkill(dev);
  246. return sprintf(buf, "%s\n", rfkill->name);
  247. }
  248. static const char *rfkill_get_type_str(enum rfkill_type type)
  249. {
  250. switch (type) {
  251. case RFKILL_TYPE_WLAN:
  252. return "wlan";
  253. case RFKILL_TYPE_BLUETOOTH:
  254. return "bluetooth";
  255. case RFKILL_TYPE_UWB:
  256. return "ultrawideband";
  257. case RFKILL_TYPE_WIMAX:
  258. return "wimax";
  259. case RFKILL_TYPE_WWAN:
  260. return "wwan";
  261. default:
  262. BUG();
  263. }
  264. }
  265. static ssize_t rfkill_type_show(struct device *dev,
  266. struct device_attribute *attr,
  267. char *buf)
  268. {
  269. struct rfkill *rfkill = to_rfkill(dev);
  270. return sprintf(buf, "%s\n", rfkill_get_type_str(rfkill->type));
  271. }
  272. static ssize_t rfkill_state_show(struct device *dev,
  273. struct device_attribute *attr,
  274. char *buf)
  275. {
  276. struct rfkill *rfkill = to_rfkill(dev);
  277. update_rfkill_state(rfkill);
  278. return sprintf(buf, "%d\n", rfkill->state);
  279. }
  280. static ssize_t rfkill_state_store(struct device *dev,
  281. struct device_attribute *attr,
  282. const char *buf, size_t count)
  283. {
  284. struct rfkill *rfkill = to_rfkill(dev);
  285. unsigned int state = simple_strtoul(buf, NULL, 0);
  286. int error;
  287. if (!capable(CAP_NET_ADMIN))
  288. return -EPERM;
  289. /* RFKILL_STATE_HARD_BLOCKED is illegal here... */
  290. if (state != RFKILL_STATE_UNBLOCKED &&
  291. state != RFKILL_STATE_SOFT_BLOCKED)
  292. return -EINVAL;
  293. if (mutex_lock_interruptible(&rfkill->mutex))
  294. return -ERESTARTSYS;
  295. error = rfkill_toggle_radio(rfkill, state, 0);
  296. mutex_unlock(&rfkill->mutex);
  297. return error ? error : count;
  298. }
  299. static ssize_t rfkill_claim_show(struct device *dev,
  300. struct device_attribute *attr,
  301. char *buf)
  302. {
  303. struct rfkill *rfkill = to_rfkill(dev);
  304. return sprintf(buf, "%d", rfkill->user_claim);
  305. }
  306. static ssize_t rfkill_claim_store(struct device *dev,
  307. struct device_attribute *attr,
  308. const char *buf, size_t count)
  309. {
  310. struct rfkill *rfkill = to_rfkill(dev);
  311. bool claim = !!simple_strtoul(buf, NULL, 0);
  312. int error;
  313. if (!capable(CAP_NET_ADMIN))
  314. return -EPERM;
  315. /*
  316. * Take the global lock to make sure the kernel is not in
  317. * the middle of rfkill_switch_all
  318. */
  319. error = mutex_lock_interruptible(&rfkill_mutex);
  320. if (error)
  321. return error;
  322. if (rfkill->user_claim_unsupported) {
  323. error = -EOPNOTSUPP;
  324. goto out_unlock;
  325. }
  326. if (rfkill->user_claim != claim) {
  327. if (!claim)
  328. rfkill_toggle_radio(rfkill,
  329. rfkill_states[rfkill->type],
  330. 0);
  331. rfkill->user_claim = claim;
  332. }
  333. out_unlock:
  334. mutex_unlock(&rfkill_mutex);
  335. return error ? error : count;
  336. }
  337. static struct device_attribute rfkill_dev_attrs[] = {
  338. __ATTR(name, S_IRUGO, rfkill_name_show, NULL),
  339. __ATTR(type, S_IRUGO, rfkill_type_show, NULL),
  340. __ATTR(state, S_IRUGO|S_IWUSR, rfkill_state_show, rfkill_state_store),
  341. __ATTR(claim, S_IRUGO|S_IWUSR, rfkill_claim_show, rfkill_claim_store),
  342. __ATTR_NULL
  343. };
  344. static void rfkill_release(struct device *dev)
  345. {
  346. struct rfkill *rfkill = to_rfkill(dev);
  347. kfree(rfkill);
  348. module_put(THIS_MODULE);
  349. }
  350. #ifdef CONFIG_PM
  351. static int rfkill_suspend(struct device *dev, pm_message_t state)
  352. {
  353. struct rfkill *rfkill = to_rfkill(dev);
  354. if (dev->power.power_state.event != state.event) {
  355. if (state.event & PM_EVENT_SLEEP) {
  356. /* Stop transmitter, keep state, no notifies */
  357. update_rfkill_state(rfkill);
  358. mutex_lock(&rfkill->mutex);
  359. rfkill->toggle_radio(rfkill->data,
  360. RFKILL_STATE_SOFT_BLOCKED);
  361. mutex_unlock(&rfkill->mutex);
  362. }
  363. dev->power.power_state = state;
  364. }
  365. return 0;
  366. }
  367. static int rfkill_resume(struct device *dev)
  368. {
  369. struct rfkill *rfkill = to_rfkill(dev);
  370. if (dev->power.power_state.event != PM_EVENT_ON) {
  371. mutex_lock(&rfkill->mutex);
  372. /* restore radio state AND notify everybody */
  373. rfkill_toggle_radio(rfkill, rfkill->state, 1);
  374. mutex_unlock(&rfkill->mutex);
  375. }
  376. dev->power.power_state = PMSG_ON;
  377. return 0;
  378. }
  379. #else
  380. #define rfkill_suspend NULL
  381. #define rfkill_resume NULL
  382. #endif
  383. static int rfkill_blocking_uevent_notifier(struct notifier_block *nb,
  384. unsigned long eventid,
  385. void *data)
  386. {
  387. struct rfkill *rfkill = (struct rfkill *)data;
  388. switch (eventid) {
  389. case RFKILL_STATE_CHANGED:
  390. kobject_uevent(&rfkill->dev.kobj, KOBJ_CHANGE);
  391. break;
  392. default:
  393. break;
  394. }
  395. return NOTIFY_DONE;
  396. }
  397. static struct notifier_block rfkill_blocking_uevent_nb = {
  398. .notifier_call = rfkill_blocking_uevent_notifier,
  399. .priority = 0,
  400. };
  401. static int rfkill_dev_uevent(struct device *dev, struct kobj_uevent_env *env)
  402. {
  403. struct rfkill *rfkill = to_rfkill(dev);
  404. int error;
  405. error = add_uevent_var(env, "RFKILL_NAME=%s", rfkill->name);
  406. if (error)
  407. return error;
  408. error = add_uevent_var(env, "RFKILL_TYPE=%s",
  409. rfkill_get_type_str(rfkill->type));
  410. if (error)
  411. return error;
  412. error = add_uevent_var(env, "RFKILL_STATE=%d", rfkill->state);
  413. return error;
  414. }
  415. static struct class rfkill_class = {
  416. .name = "rfkill",
  417. .dev_release = rfkill_release,
  418. .dev_attrs = rfkill_dev_attrs,
  419. .suspend = rfkill_suspend,
  420. .resume = rfkill_resume,
  421. .dev_uevent = rfkill_dev_uevent,
  422. };
  423. static int rfkill_add_switch(struct rfkill *rfkill)
  424. {
  425. mutex_lock(&rfkill_mutex);
  426. rfkill_toggle_radio(rfkill, rfkill_states[rfkill->type], 0);
  427. list_add_tail(&rfkill->node, &rfkill_list);
  428. mutex_unlock(&rfkill_mutex);
  429. return 0;
  430. }
  431. static void rfkill_remove_switch(struct rfkill *rfkill)
  432. {
  433. mutex_lock(&rfkill_mutex);
  434. list_del_init(&rfkill->node);
  435. rfkill_toggle_radio(rfkill, RFKILL_STATE_SOFT_BLOCKED, 1);
  436. mutex_unlock(&rfkill_mutex);
  437. }
  438. /**
  439. * rfkill_allocate - allocate memory for rfkill structure.
  440. * @parent: device that has rf switch on it
  441. * @type: type of the switch (RFKILL_TYPE_*)
  442. *
  443. * This function should be called by the network driver when it needs
  444. * rfkill structure. Once the structure is allocated the driver shoud
  445. * finish its initialization by setting name, private data, enable_radio
  446. * and disable_radio methods and then register it with rfkill_register().
  447. * NOTE: If registration fails the structure shoudl be freed by calling
  448. * rfkill_free() otherwise rfkill_unregister() should be used.
  449. */
  450. struct rfkill *rfkill_allocate(struct device *parent, enum rfkill_type type)
  451. {
  452. struct rfkill *rfkill;
  453. struct device *dev;
  454. rfkill = kzalloc(sizeof(struct rfkill), GFP_KERNEL);
  455. if (!rfkill)
  456. return NULL;
  457. mutex_init(&rfkill->mutex);
  458. INIT_LIST_HEAD(&rfkill->node);
  459. rfkill->type = type;
  460. dev = &rfkill->dev;
  461. dev->class = &rfkill_class;
  462. dev->parent = parent;
  463. device_initialize(dev);
  464. __module_get(THIS_MODULE);
  465. return rfkill;
  466. }
  467. EXPORT_SYMBOL(rfkill_allocate);
  468. /**
  469. * rfkill_free - Mark rfkill structure for deletion
  470. * @rfkill: rfkill structure to be destroyed
  471. *
  472. * Decrements reference count of rfkill structure so it is destroyed.
  473. * Note that rfkill_free() should _not_ be called after rfkill_unregister().
  474. */
  475. void rfkill_free(struct rfkill *rfkill)
  476. {
  477. if (rfkill)
  478. put_device(&rfkill->dev);
  479. }
  480. EXPORT_SYMBOL(rfkill_free);
  481. static void rfkill_led_trigger_register(struct rfkill *rfkill)
  482. {
  483. #ifdef CONFIG_RFKILL_LEDS
  484. int error;
  485. rfkill->led_trigger.name = rfkill->dev.bus_id;
  486. error = led_trigger_register(&rfkill->led_trigger);
  487. if (error)
  488. rfkill->led_trigger.name = NULL;
  489. #endif /* CONFIG_RFKILL_LEDS */
  490. }
  491. static void rfkill_led_trigger_unregister(struct rfkill *rfkill)
  492. {
  493. #ifdef CONFIG_RFKILL_LEDS
  494. if (rfkill->led_trigger.name)
  495. led_trigger_unregister(&rfkill->led_trigger);
  496. #endif
  497. }
  498. /**
  499. * rfkill_register - Register a rfkill structure.
  500. * @rfkill: rfkill structure to be registered
  501. *
  502. * This function should be called by the network driver when the rfkill
  503. * structure needs to be registered. Immediately from registration the
  504. * switch driver should be able to service calls to toggle_radio.
  505. */
  506. int rfkill_register(struct rfkill *rfkill)
  507. {
  508. static atomic_t rfkill_no = ATOMIC_INIT(0);
  509. struct device *dev = &rfkill->dev;
  510. int error;
  511. if (!rfkill->toggle_radio)
  512. return -EINVAL;
  513. if (rfkill->type >= RFKILL_TYPE_MAX)
  514. return -EINVAL;
  515. snprintf(dev->bus_id, sizeof(dev->bus_id),
  516. "rfkill%ld", (long)atomic_inc_return(&rfkill_no) - 1);
  517. rfkill_led_trigger_register(rfkill);
  518. error = rfkill_add_switch(rfkill);
  519. if (error) {
  520. rfkill_led_trigger_unregister(rfkill);
  521. return error;
  522. }
  523. error = device_add(dev);
  524. if (error) {
  525. rfkill_led_trigger_unregister(rfkill);
  526. rfkill_remove_switch(rfkill);
  527. return error;
  528. }
  529. return 0;
  530. }
  531. EXPORT_SYMBOL(rfkill_register);
  532. /**
  533. * rfkill_unregister - Unregister a rfkill structure.
  534. * @rfkill: rfkill structure to be unregistered
  535. *
  536. * This function should be called by the network driver during device
  537. * teardown to destroy rfkill structure. Note that rfkill_free() should
  538. * _not_ be called after rfkill_unregister().
  539. */
  540. void rfkill_unregister(struct rfkill *rfkill)
  541. {
  542. device_del(&rfkill->dev);
  543. rfkill_remove_switch(rfkill);
  544. rfkill_led_trigger_unregister(rfkill);
  545. put_device(&rfkill->dev);
  546. }
  547. EXPORT_SYMBOL(rfkill_unregister);
  548. /*
  549. * Rfkill module initialization/deinitialization.
  550. */
  551. static int __init rfkill_init(void)
  552. {
  553. int error;
  554. int i;
  555. /* RFKILL_STATE_HARD_BLOCKED is illegal here... */
  556. if (rfkill_default_state != RFKILL_STATE_SOFT_BLOCKED &&
  557. rfkill_default_state != RFKILL_STATE_UNBLOCKED)
  558. return -EINVAL;
  559. for (i = 0; i < ARRAY_SIZE(rfkill_states); i++)
  560. rfkill_states[i] = rfkill_default_state;
  561. error = class_register(&rfkill_class);
  562. if (error) {
  563. printk(KERN_ERR "rfkill: unable to register rfkill class\n");
  564. return error;
  565. }
  566. register_rfkill_notifier(&rfkill_blocking_uevent_nb);
  567. return 0;
  568. }
  569. static void __exit rfkill_exit(void)
  570. {
  571. unregister_rfkill_notifier(&rfkill_blocking_uevent_nb);
  572. class_unregister(&rfkill_class);
  573. }
  574. subsys_initcall(rfkill_init);
  575. module_exit(rfkill_exit);