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. * calls toggle_radio taking into account a lot of "small"
  116. * details.
  117. * @rfkill: the rfkill struct to use
  118. * @force: calls toggle_radio even if cache says it is not needed,
  119. * and also makes sure notifications of the state will be
  120. * sent even if it didn't change
  121. * @state: the new state to call toggle_radio() with
  122. *
  123. * This wrappen protects and enforces the API for toggle_radio
  124. * calls. Note that @force cannot override a (possibly cached)
  125. * state of RFKILL_STATE_HARD_BLOCKED. Any device making use of
  126. * RFKILL_STATE_HARD_BLOCKED implements either get_state() or
  127. * rfkill_force_state(), so the cache either is bypassed or valid.
  128. *
  129. * Note that we do call toggle_radio for RFKILL_STATE_SOFT_BLOCKED
  130. * even if the radio is in RFKILL_STATE_HARD_BLOCKED state, so as to
  131. * give the driver a hint that it should double-BLOCK the transmitter.
  132. *
  133. * Caller must have aquired rfkill_mutex.
  134. */
  135. static int rfkill_toggle_radio(struct rfkill *rfkill,
  136. enum rfkill_state state,
  137. int force)
  138. {
  139. int retval = 0;
  140. enum rfkill_state oldstate, newstate;
  141. oldstate = rfkill->state;
  142. if (rfkill->get_state && !force &&
  143. !rfkill->get_state(rfkill->data, &newstate))
  144. rfkill->state = newstate;
  145. switch (state) {
  146. case RFKILL_STATE_HARD_BLOCKED:
  147. /* typically happens when refreshing hardware state,
  148. * such as on resume */
  149. state = RFKILL_STATE_SOFT_BLOCKED;
  150. break;
  151. case RFKILL_STATE_UNBLOCKED:
  152. /* force can't override this, only rfkill_force_state() can */
  153. if (rfkill->state == RFKILL_STATE_HARD_BLOCKED)
  154. return -EPERM;
  155. break;
  156. case RFKILL_STATE_SOFT_BLOCKED:
  157. /* nothing to do, we want to give drivers the hint to double
  158. * BLOCK even a transmitter that is already in state
  159. * RFKILL_STATE_HARD_BLOCKED */
  160. break;
  161. }
  162. if (force || state != rfkill->state) {
  163. retval = rfkill->toggle_radio(rfkill->data, state);
  164. /* never allow a HARD->SOFT downgrade! */
  165. if (!retval && rfkill->state != RFKILL_STATE_HARD_BLOCKED)
  166. rfkill->state = state;
  167. }
  168. if (force || rfkill->state != oldstate) {
  169. rfkill_led_trigger(rfkill, rfkill->state);
  170. notify_rfkill_state_change(rfkill);
  171. }
  172. return retval;
  173. }
  174. /**
  175. * rfkill_switch_all - Toggle state of all switches of given type
  176. * @type: type of interfaces to be affeceted
  177. * @state: the new state
  178. *
  179. * This function toggles state of all switches of given type unless
  180. * a specific switch is claimed by userspace in which case it is
  181. * left alone.
  182. */
  183. void rfkill_switch_all(enum rfkill_type type, enum rfkill_state state)
  184. {
  185. struct rfkill *rfkill;
  186. mutex_lock(&rfkill_mutex);
  187. rfkill_states[type] = state;
  188. list_for_each_entry(rfkill, &rfkill_list, node) {
  189. if ((!rfkill->user_claim) && (rfkill->type == type))
  190. rfkill_toggle_radio(rfkill, state, 0);
  191. }
  192. mutex_unlock(&rfkill_mutex);
  193. }
  194. EXPORT_SYMBOL(rfkill_switch_all);
  195. /**
  196. * rfkill_epo - emergency power off all transmitters
  197. *
  198. * This kicks all rfkill devices to RFKILL_STATE_SOFT_BLOCKED, ignoring
  199. * everything in its path but rfkill_mutex.
  200. */
  201. void rfkill_epo(void)
  202. {
  203. struct rfkill *rfkill;
  204. mutex_lock(&rfkill_mutex);
  205. list_for_each_entry(rfkill, &rfkill_list, node) {
  206. rfkill_toggle_radio(rfkill, RFKILL_STATE_SOFT_BLOCKED, 1);
  207. }
  208. mutex_unlock(&rfkill_mutex);
  209. }
  210. EXPORT_SYMBOL_GPL(rfkill_epo);
  211. /**
  212. * rfkill_force_state - Force the internal rfkill radio state
  213. * @rfkill: pointer to the rfkill class to modify.
  214. * @state: the current radio state the class should be forced to.
  215. *
  216. * This function updates the internal state of the radio cached
  217. * by the rfkill class. It should be used when the driver gets
  218. * a notification by the firmware/hardware of the current *real*
  219. * state of the radio rfkill switch.
  220. *
  221. * It may not be called from an atomic context.
  222. */
  223. int rfkill_force_state(struct rfkill *rfkill, enum rfkill_state state)
  224. {
  225. enum rfkill_state oldstate;
  226. if (state != RFKILL_STATE_SOFT_BLOCKED &&
  227. state != RFKILL_STATE_UNBLOCKED &&
  228. state != RFKILL_STATE_HARD_BLOCKED)
  229. return -EINVAL;
  230. mutex_lock(&rfkill->mutex);
  231. oldstate = rfkill->state;
  232. rfkill->state = state;
  233. if (state != oldstate)
  234. notify_rfkill_state_change(rfkill);
  235. mutex_unlock(&rfkill->mutex);
  236. return 0;
  237. }
  238. EXPORT_SYMBOL(rfkill_force_state);
  239. static ssize_t rfkill_name_show(struct device *dev,
  240. struct device_attribute *attr,
  241. char *buf)
  242. {
  243. struct rfkill *rfkill = to_rfkill(dev);
  244. return sprintf(buf, "%s\n", rfkill->name);
  245. }
  246. static const char *rfkill_get_type_str(enum rfkill_type type)
  247. {
  248. switch (type) {
  249. case RFKILL_TYPE_WLAN:
  250. return "wlan";
  251. case RFKILL_TYPE_BLUETOOTH:
  252. return "bluetooth";
  253. case RFKILL_TYPE_UWB:
  254. return "ultrawideband";
  255. case RFKILL_TYPE_WIMAX:
  256. return "wimax";
  257. case RFKILL_TYPE_WWAN:
  258. return "wwan";
  259. default:
  260. BUG();
  261. }
  262. }
  263. static ssize_t rfkill_type_show(struct device *dev,
  264. struct device_attribute *attr,
  265. char *buf)
  266. {
  267. struct rfkill *rfkill = to_rfkill(dev);
  268. return sprintf(buf, "%s\n", rfkill_get_type_str(rfkill->type));
  269. }
  270. static ssize_t rfkill_state_show(struct device *dev,
  271. struct device_attribute *attr,
  272. char *buf)
  273. {
  274. struct rfkill *rfkill = to_rfkill(dev);
  275. update_rfkill_state(rfkill);
  276. return sprintf(buf, "%d\n", rfkill->state);
  277. }
  278. static ssize_t rfkill_state_store(struct device *dev,
  279. struct device_attribute *attr,
  280. const char *buf, size_t count)
  281. {
  282. struct rfkill *rfkill = to_rfkill(dev);
  283. unsigned int state = simple_strtoul(buf, NULL, 0);
  284. int error;
  285. if (!capable(CAP_NET_ADMIN))
  286. return -EPERM;
  287. /* RFKILL_STATE_HARD_BLOCKED is illegal here... */
  288. if (state != RFKILL_STATE_UNBLOCKED &&
  289. state != RFKILL_STATE_SOFT_BLOCKED)
  290. return -EINVAL;
  291. if (mutex_lock_interruptible(&rfkill->mutex))
  292. return -ERESTARTSYS;
  293. error = rfkill_toggle_radio(rfkill, state, 0);
  294. mutex_unlock(&rfkill->mutex);
  295. return error ? error : count;
  296. }
  297. static ssize_t rfkill_claim_show(struct device *dev,
  298. struct device_attribute *attr,
  299. char *buf)
  300. {
  301. struct rfkill *rfkill = to_rfkill(dev);
  302. return sprintf(buf, "%d", rfkill->user_claim);
  303. }
  304. static ssize_t rfkill_claim_store(struct device *dev,
  305. struct device_attribute *attr,
  306. const char *buf, size_t count)
  307. {
  308. struct rfkill *rfkill = to_rfkill(dev);
  309. bool claim = !!simple_strtoul(buf, NULL, 0);
  310. int error;
  311. if (!capable(CAP_NET_ADMIN))
  312. return -EPERM;
  313. /*
  314. * Take the global lock to make sure the kernel is not in
  315. * the middle of rfkill_switch_all
  316. */
  317. error = mutex_lock_interruptible(&rfkill_mutex);
  318. if (error)
  319. return error;
  320. if (rfkill->user_claim_unsupported) {
  321. error = -EOPNOTSUPP;
  322. goto out_unlock;
  323. }
  324. if (rfkill->user_claim != claim) {
  325. if (!claim)
  326. rfkill_toggle_radio(rfkill,
  327. rfkill_states[rfkill->type],
  328. 0);
  329. rfkill->user_claim = claim;
  330. }
  331. out_unlock:
  332. mutex_unlock(&rfkill_mutex);
  333. return error ? error : count;
  334. }
  335. static struct device_attribute rfkill_dev_attrs[] = {
  336. __ATTR(name, S_IRUGO, rfkill_name_show, NULL),
  337. __ATTR(type, S_IRUGO, rfkill_type_show, NULL),
  338. __ATTR(state, S_IRUGO|S_IWUSR, rfkill_state_show, rfkill_state_store),
  339. __ATTR(claim, S_IRUGO|S_IWUSR, rfkill_claim_show, rfkill_claim_store),
  340. __ATTR_NULL
  341. };
  342. static void rfkill_release(struct device *dev)
  343. {
  344. struct rfkill *rfkill = to_rfkill(dev);
  345. kfree(rfkill);
  346. module_put(THIS_MODULE);
  347. }
  348. #ifdef CONFIG_PM
  349. static int rfkill_suspend(struct device *dev, pm_message_t state)
  350. {
  351. struct rfkill *rfkill = to_rfkill(dev);
  352. if (dev->power.power_state.event != state.event) {
  353. if (state.event & PM_EVENT_SLEEP) {
  354. /* Stop transmitter, keep state, no notifies */
  355. update_rfkill_state(rfkill);
  356. mutex_lock(&rfkill->mutex);
  357. rfkill->toggle_radio(rfkill->data,
  358. RFKILL_STATE_SOFT_BLOCKED);
  359. mutex_unlock(&rfkill->mutex);
  360. }
  361. dev->power.power_state = state;
  362. }
  363. return 0;
  364. }
  365. static int rfkill_resume(struct device *dev)
  366. {
  367. struct rfkill *rfkill = to_rfkill(dev);
  368. if (dev->power.power_state.event != PM_EVENT_ON) {
  369. mutex_lock(&rfkill->mutex);
  370. /* restore radio state AND notify everybody */
  371. rfkill_toggle_radio(rfkill, rfkill->state, 1);
  372. mutex_unlock(&rfkill->mutex);
  373. }
  374. dev->power.power_state = PMSG_ON;
  375. return 0;
  376. }
  377. #else
  378. #define rfkill_suspend NULL
  379. #define rfkill_resume NULL
  380. #endif
  381. static int rfkill_blocking_uevent_notifier(struct notifier_block *nb,
  382. unsigned long eventid,
  383. void *data)
  384. {
  385. struct rfkill *rfkill = (struct rfkill *)data;
  386. switch (eventid) {
  387. case RFKILL_STATE_CHANGED:
  388. kobject_uevent(&rfkill->dev.kobj, KOBJ_CHANGE);
  389. break;
  390. default:
  391. break;
  392. }
  393. return NOTIFY_DONE;
  394. }
  395. static struct notifier_block rfkill_blocking_uevent_nb = {
  396. .notifier_call = rfkill_blocking_uevent_notifier,
  397. .priority = 0,
  398. };
  399. static int rfkill_dev_uevent(struct device *dev, struct kobj_uevent_env *env)
  400. {
  401. struct rfkill *rfkill = to_rfkill(dev);
  402. int error;
  403. error = add_uevent_var(env, "RFKILL_NAME=%s", rfkill->name);
  404. if (error)
  405. return error;
  406. error = add_uevent_var(env, "RFKILL_TYPE=%s",
  407. rfkill_get_type_str(rfkill->type));
  408. if (error)
  409. return error;
  410. error = add_uevent_var(env, "RFKILL_STATE=%d", rfkill->state);
  411. return error;
  412. }
  413. static struct class rfkill_class = {
  414. .name = "rfkill",
  415. .dev_release = rfkill_release,
  416. .dev_attrs = rfkill_dev_attrs,
  417. .suspend = rfkill_suspend,
  418. .resume = rfkill_resume,
  419. .dev_uevent = rfkill_dev_uevent,
  420. };
  421. static int rfkill_add_switch(struct rfkill *rfkill)
  422. {
  423. int error;
  424. mutex_lock(&rfkill_mutex);
  425. error = rfkill_toggle_radio(rfkill, rfkill_states[rfkill->type], 0);
  426. if (!error)
  427. list_add_tail(&rfkill->node, &rfkill_list);
  428. mutex_unlock(&rfkill_mutex);
  429. return error;
  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);