core.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369
  1. /*
  2. * Copyright (C) 2006 - 2007 Ivo van Doorn
  3. * Copyright (C) 2007 Dmitry Torokhov
  4. * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <linux/kernel.h>
  20. #include <linux/module.h>
  21. #include <linux/init.h>
  22. #include <linux/workqueue.h>
  23. #include <linux/capability.h>
  24. #include <linux/list.h>
  25. #include <linux/mutex.h>
  26. #include <linux/rfkill.h>
  27. #include <linux/sched.h>
  28. #include <linux/spinlock.h>
  29. #include <linux/device.h>
  30. #include <linux/miscdevice.h>
  31. #include <linux/wait.h>
  32. #include <linux/poll.h>
  33. #include <linux/fs.h>
  34. #include <linux/slab.h>
  35. #include "rfkill.h"
  36. #define POLL_INTERVAL (5 * HZ)
  37. #define RFKILL_BLOCK_HW BIT(0)
  38. #define RFKILL_BLOCK_SW BIT(1)
  39. #define RFKILL_BLOCK_SW_PREV BIT(2)
  40. #define RFKILL_BLOCK_ANY (RFKILL_BLOCK_HW |\
  41. RFKILL_BLOCK_SW |\
  42. RFKILL_BLOCK_SW_PREV)
  43. #define RFKILL_BLOCK_SW_SETCALL BIT(31)
  44. struct rfkill {
  45. spinlock_t lock;
  46. enum rfkill_type type;
  47. unsigned long state;
  48. u32 idx;
  49. bool registered;
  50. bool persistent;
  51. bool polling_paused;
  52. bool suspended;
  53. const struct rfkill_ops *ops;
  54. void *data;
  55. #ifdef CONFIG_RFKILL_LEDS
  56. struct led_trigger led_trigger;
  57. const char *ledtrigname;
  58. #endif
  59. struct device dev;
  60. struct list_head node;
  61. struct delayed_work poll_work;
  62. struct work_struct uevent_work;
  63. struct work_struct sync_work;
  64. char name[];
  65. };
  66. #define to_rfkill(d) container_of(d, struct rfkill, dev)
  67. struct rfkill_int_event {
  68. struct list_head list;
  69. struct rfkill_event ev;
  70. };
  71. struct rfkill_data {
  72. struct list_head list;
  73. struct list_head events;
  74. struct mutex mtx;
  75. wait_queue_head_t read_wait;
  76. bool input_handler;
  77. };
  78. MODULE_AUTHOR("Ivo van Doorn <IvDoorn@gmail.com>");
  79. MODULE_AUTHOR("Johannes Berg <johannes@sipsolutions.net>");
  80. MODULE_DESCRIPTION("RF switch support");
  81. MODULE_LICENSE("GPL");
  82. /*
  83. * The locking here should be made much smarter, we currently have
  84. * a bit of a stupid situation because drivers might want to register
  85. * the rfkill struct under their own lock, and take this lock during
  86. * rfkill method calls -- which will cause an AB-BA deadlock situation.
  87. *
  88. * To fix that, we need to rework this code here to be mostly lock-free
  89. * and only use the mutex for list manipulations, not to protect the
  90. * various other global variables. Then we can avoid holding the mutex
  91. * around driver operations, and all is happy.
  92. */
  93. static LIST_HEAD(rfkill_list); /* list of registered rf switches */
  94. static DEFINE_MUTEX(rfkill_global_mutex);
  95. static LIST_HEAD(rfkill_fds); /* list of open fds of /dev/rfkill */
  96. static unsigned int rfkill_default_state = 1;
  97. module_param_named(default_state, rfkill_default_state, uint, 0444);
  98. MODULE_PARM_DESC(default_state,
  99. "Default initial state for all radio types, 0 = radio off");
  100. static struct {
  101. bool cur, sav;
  102. } rfkill_global_states[NUM_RFKILL_TYPES];
  103. static bool rfkill_epo_lock_active;
  104. #ifdef CONFIG_RFKILL_LEDS
  105. static void rfkill_led_trigger_event(struct rfkill *rfkill)
  106. {
  107. struct led_trigger *trigger;
  108. if (!rfkill->registered)
  109. return;
  110. trigger = &rfkill->led_trigger;
  111. if (rfkill->state & RFKILL_BLOCK_ANY)
  112. led_trigger_event(trigger, LED_OFF);
  113. else
  114. led_trigger_event(trigger, LED_FULL);
  115. }
  116. static void rfkill_led_trigger_activate(struct led_classdev *led)
  117. {
  118. struct rfkill *rfkill;
  119. rfkill = container_of(led->trigger, struct rfkill, led_trigger);
  120. rfkill_led_trigger_event(rfkill);
  121. }
  122. const char *rfkill_get_led_trigger_name(struct rfkill *rfkill)
  123. {
  124. return rfkill->led_trigger.name;
  125. }
  126. EXPORT_SYMBOL(rfkill_get_led_trigger_name);
  127. void rfkill_set_led_trigger_name(struct rfkill *rfkill, const char *name)
  128. {
  129. BUG_ON(!rfkill);
  130. rfkill->ledtrigname = name;
  131. }
  132. EXPORT_SYMBOL(rfkill_set_led_trigger_name);
  133. static int rfkill_led_trigger_register(struct rfkill *rfkill)
  134. {
  135. rfkill->led_trigger.name = rfkill->ledtrigname
  136. ? : dev_name(&rfkill->dev);
  137. rfkill->led_trigger.activate = rfkill_led_trigger_activate;
  138. return led_trigger_register(&rfkill->led_trigger);
  139. }
  140. static void rfkill_led_trigger_unregister(struct rfkill *rfkill)
  141. {
  142. led_trigger_unregister(&rfkill->led_trigger);
  143. }
  144. static struct led_trigger rfkill_any_led_trigger;
  145. static struct work_struct rfkill_any_work;
  146. static void rfkill_any_led_trigger_worker(struct work_struct *work)
  147. {
  148. enum led_brightness brightness = LED_OFF;
  149. struct rfkill *rfkill;
  150. mutex_lock(&rfkill_global_mutex);
  151. list_for_each_entry(rfkill, &rfkill_list, node) {
  152. if (!(rfkill->state & RFKILL_BLOCK_ANY)) {
  153. brightness = LED_FULL;
  154. break;
  155. }
  156. }
  157. mutex_unlock(&rfkill_global_mutex);
  158. led_trigger_event(&rfkill_any_led_trigger, brightness);
  159. }
  160. static void rfkill_any_led_trigger_event(void)
  161. {
  162. schedule_work(&rfkill_any_work);
  163. }
  164. static void rfkill_any_led_trigger_activate(struct led_classdev *led_cdev)
  165. {
  166. rfkill_any_led_trigger_event();
  167. }
  168. static int rfkill_any_led_trigger_register(void)
  169. {
  170. INIT_WORK(&rfkill_any_work, rfkill_any_led_trigger_worker);
  171. rfkill_any_led_trigger.name = "rfkill-any";
  172. rfkill_any_led_trigger.activate = rfkill_any_led_trigger_activate;
  173. return led_trigger_register(&rfkill_any_led_trigger);
  174. }
  175. static void rfkill_any_led_trigger_unregister(void)
  176. {
  177. led_trigger_unregister(&rfkill_any_led_trigger);
  178. cancel_work_sync(&rfkill_any_work);
  179. }
  180. #else
  181. static void rfkill_led_trigger_event(struct rfkill *rfkill)
  182. {
  183. }
  184. static inline int rfkill_led_trigger_register(struct rfkill *rfkill)
  185. {
  186. return 0;
  187. }
  188. static inline void rfkill_led_trigger_unregister(struct rfkill *rfkill)
  189. {
  190. }
  191. static void rfkill_any_led_trigger_event(void)
  192. {
  193. }
  194. static int rfkill_any_led_trigger_register(void)
  195. {
  196. return 0;
  197. }
  198. static void rfkill_any_led_trigger_unregister(void)
  199. {
  200. }
  201. #endif /* CONFIG_RFKILL_LEDS */
  202. static void rfkill_fill_event(struct rfkill_event *ev, struct rfkill *rfkill,
  203. enum rfkill_operation op)
  204. {
  205. unsigned long flags;
  206. ev->idx = rfkill->idx;
  207. ev->type = rfkill->type;
  208. ev->op = op;
  209. spin_lock_irqsave(&rfkill->lock, flags);
  210. ev->hard = !!(rfkill->state & RFKILL_BLOCK_HW);
  211. ev->soft = !!(rfkill->state & (RFKILL_BLOCK_SW |
  212. RFKILL_BLOCK_SW_PREV));
  213. spin_unlock_irqrestore(&rfkill->lock, flags);
  214. }
  215. static void rfkill_send_events(struct rfkill *rfkill, enum rfkill_operation op)
  216. {
  217. struct rfkill_data *data;
  218. struct rfkill_int_event *ev;
  219. list_for_each_entry(data, &rfkill_fds, list) {
  220. ev = kzalloc(sizeof(*ev), GFP_KERNEL);
  221. if (!ev)
  222. continue;
  223. rfkill_fill_event(&ev->ev, rfkill, op);
  224. mutex_lock(&data->mtx);
  225. list_add_tail(&ev->list, &data->events);
  226. mutex_unlock(&data->mtx);
  227. wake_up_interruptible(&data->read_wait);
  228. }
  229. }
  230. static void rfkill_event(struct rfkill *rfkill)
  231. {
  232. if (!rfkill->registered)
  233. return;
  234. kobject_uevent(&rfkill->dev.kobj, KOBJ_CHANGE);
  235. /* also send event to /dev/rfkill */
  236. rfkill_send_events(rfkill, RFKILL_OP_CHANGE);
  237. }
  238. /**
  239. * rfkill_set_block - wrapper for set_block method
  240. *
  241. * @rfkill: the rfkill struct to use
  242. * @blocked: the new software state
  243. *
  244. * Calls the set_block method (when applicable) and handles notifications
  245. * etc. as well.
  246. */
  247. static void rfkill_set_block(struct rfkill *rfkill, bool blocked)
  248. {
  249. unsigned long flags;
  250. bool prev, curr;
  251. int err;
  252. if (unlikely(rfkill->dev.power.power_state.event & PM_EVENT_SLEEP))
  253. return;
  254. /*
  255. * Some platforms (...!) generate input events which affect the
  256. * _hard_ kill state -- whenever something tries to change the
  257. * current software state query the hardware state too.
  258. */
  259. if (rfkill->ops->query)
  260. rfkill->ops->query(rfkill, rfkill->data);
  261. spin_lock_irqsave(&rfkill->lock, flags);
  262. prev = rfkill->state & RFKILL_BLOCK_SW;
  263. if (prev)
  264. rfkill->state |= RFKILL_BLOCK_SW_PREV;
  265. else
  266. rfkill->state &= ~RFKILL_BLOCK_SW_PREV;
  267. if (blocked)
  268. rfkill->state |= RFKILL_BLOCK_SW;
  269. else
  270. rfkill->state &= ~RFKILL_BLOCK_SW;
  271. rfkill->state |= RFKILL_BLOCK_SW_SETCALL;
  272. spin_unlock_irqrestore(&rfkill->lock, flags);
  273. err = rfkill->ops->set_block(rfkill->data, blocked);
  274. spin_lock_irqsave(&rfkill->lock, flags);
  275. if (err) {
  276. /*
  277. * Failed -- reset status to _PREV, which may be different
  278. * from what we have set _PREV to earlier in this function
  279. * if rfkill_set_sw_state was invoked.
  280. */
  281. if (rfkill->state & RFKILL_BLOCK_SW_PREV)
  282. rfkill->state |= RFKILL_BLOCK_SW;
  283. else
  284. rfkill->state &= ~RFKILL_BLOCK_SW;
  285. }
  286. rfkill->state &= ~RFKILL_BLOCK_SW_SETCALL;
  287. rfkill->state &= ~RFKILL_BLOCK_SW_PREV;
  288. curr = rfkill->state & RFKILL_BLOCK_SW;
  289. spin_unlock_irqrestore(&rfkill->lock, flags);
  290. rfkill_led_trigger_event(rfkill);
  291. rfkill_any_led_trigger_event();
  292. if (prev != curr)
  293. rfkill_event(rfkill);
  294. }
  295. static void rfkill_update_global_state(enum rfkill_type type, bool blocked)
  296. {
  297. int i;
  298. if (type != RFKILL_TYPE_ALL) {
  299. rfkill_global_states[type].cur = blocked;
  300. return;
  301. }
  302. for (i = 0; i < NUM_RFKILL_TYPES; i++)
  303. rfkill_global_states[i].cur = blocked;
  304. }
  305. #ifdef CONFIG_RFKILL_INPUT
  306. static atomic_t rfkill_input_disabled = ATOMIC_INIT(0);
  307. /**
  308. * __rfkill_switch_all - Toggle state of all switches of given type
  309. * @type: type of interfaces to be affected
  310. * @blocked: the new state
  311. *
  312. * This function sets the state of all switches of given type,
  313. * unless a specific switch is suspended.
  314. *
  315. * Caller must have acquired rfkill_global_mutex.
  316. */
  317. static void __rfkill_switch_all(const enum rfkill_type type, bool blocked)
  318. {
  319. struct rfkill *rfkill;
  320. rfkill_update_global_state(type, blocked);
  321. list_for_each_entry(rfkill, &rfkill_list, node) {
  322. if (rfkill->type != type && type != RFKILL_TYPE_ALL)
  323. continue;
  324. rfkill_set_block(rfkill, blocked);
  325. }
  326. }
  327. /**
  328. * rfkill_switch_all - Toggle state of all switches of given type
  329. * @type: type of interfaces to be affected
  330. * @blocked: the new state
  331. *
  332. * Acquires rfkill_global_mutex and calls __rfkill_switch_all(@type, @state).
  333. * Please refer to __rfkill_switch_all() for details.
  334. *
  335. * Does nothing if the EPO lock is active.
  336. */
  337. void rfkill_switch_all(enum rfkill_type type, bool blocked)
  338. {
  339. if (atomic_read(&rfkill_input_disabled))
  340. return;
  341. mutex_lock(&rfkill_global_mutex);
  342. if (!rfkill_epo_lock_active)
  343. __rfkill_switch_all(type, blocked);
  344. mutex_unlock(&rfkill_global_mutex);
  345. }
  346. /**
  347. * rfkill_epo - emergency power off all transmitters
  348. *
  349. * This kicks all non-suspended rfkill devices to RFKILL_STATE_SOFT_BLOCKED,
  350. * ignoring everything in its path but rfkill_global_mutex and rfkill->mutex.
  351. *
  352. * The global state before the EPO is saved and can be restored later
  353. * using rfkill_restore_states().
  354. */
  355. void rfkill_epo(void)
  356. {
  357. struct rfkill *rfkill;
  358. int i;
  359. if (atomic_read(&rfkill_input_disabled))
  360. return;
  361. mutex_lock(&rfkill_global_mutex);
  362. rfkill_epo_lock_active = true;
  363. list_for_each_entry(rfkill, &rfkill_list, node)
  364. rfkill_set_block(rfkill, true);
  365. for (i = 0; i < NUM_RFKILL_TYPES; i++) {
  366. rfkill_global_states[i].sav = rfkill_global_states[i].cur;
  367. rfkill_global_states[i].cur = true;
  368. }
  369. mutex_unlock(&rfkill_global_mutex);
  370. }
  371. /**
  372. * rfkill_restore_states - restore global states
  373. *
  374. * Restore (and sync switches to) the global state from the
  375. * states in rfkill_default_states. This can undo the effects of
  376. * a call to rfkill_epo().
  377. */
  378. void rfkill_restore_states(void)
  379. {
  380. int i;
  381. if (atomic_read(&rfkill_input_disabled))
  382. return;
  383. mutex_lock(&rfkill_global_mutex);
  384. rfkill_epo_lock_active = false;
  385. for (i = 0; i < NUM_RFKILL_TYPES; i++)
  386. __rfkill_switch_all(i, rfkill_global_states[i].sav);
  387. mutex_unlock(&rfkill_global_mutex);
  388. }
  389. /**
  390. * rfkill_remove_epo_lock - unlock state changes
  391. *
  392. * Used by rfkill-input manually unlock state changes, when
  393. * the EPO switch is deactivated.
  394. */
  395. void rfkill_remove_epo_lock(void)
  396. {
  397. if (atomic_read(&rfkill_input_disabled))
  398. return;
  399. mutex_lock(&rfkill_global_mutex);
  400. rfkill_epo_lock_active = false;
  401. mutex_unlock(&rfkill_global_mutex);
  402. }
  403. /**
  404. * rfkill_is_epo_lock_active - returns true EPO is active
  405. *
  406. * Returns 0 (false) if there is NOT an active EPO contidion,
  407. * and 1 (true) if there is an active EPO contition, which
  408. * locks all radios in one of the BLOCKED states.
  409. *
  410. * Can be called in atomic context.
  411. */
  412. bool rfkill_is_epo_lock_active(void)
  413. {
  414. return rfkill_epo_lock_active;
  415. }
  416. /**
  417. * rfkill_get_global_sw_state - returns global state for a type
  418. * @type: the type to get the global state of
  419. *
  420. * Returns the current global state for a given wireless
  421. * device type.
  422. */
  423. bool rfkill_get_global_sw_state(const enum rfkill_type type)
  424. {
  425. return rfkill_global_states[type].cur;
  426. }
  427. #endif
  428. bool rfkill_set_hw_state(struct rfkill *rfkill, bool blocked)
  429. {
  430. unsigned long flags;
  431. bool ret, prev;
  432. BUG_ON(!rfkill);
  433. spin_lock_irqsave(&rfkill->lock, flags);
  434. prev = !!(rfkill->state & RFKILL_BLOCK_HW);
  435. if (blocked)
  436. rfkill->state |= RFKILL_BLOCK_HW;
  437. else
  438. rfkill->state &= ~RFKILL_BLOCK_HW;
  439. ret = !!(rfkill->state & RFKILL_BLOCK_ANY);
  440. spin_unlock_irqrestore(&rfkill->lock, flags);
  441. rfkill_led_trigger_event(rfkill);
  442. rfkill_any_led_trigger_event();
  443. if (rfkill->registered && prev != blocked)
  444. schedule_work(&rfkill->uevent_work);
  445. return ret;
  446. }
  447. EXPORT_SYMBOL(rfkill_set_hw_state);
  448. static void __rfkill_set_sw_state(struct rfkill *rfkill, bool blocked)
  449. {
  450. u32 bit = RFKILL_BLOCK_SW;
  451. /* if in a ops->set_block right now, use other bit */
  452. if (rfkill->state & RFKILL_BLOCK_SW_SETCALL)
  453. bit = RFKILL_BLOCK_SW_PREV;
  454. if (blocked)
  455. rfkill->state |= bit;
  456. else
  457. rfkill->state &= ~bit;
  458. }
  459. bool rfkill_set_sw_state(struct rfkill *rfkill, bool blocked)
  460. {
  461. unsigned long flags;
  462. bool prev, hwblock;
  463. BUG_ON(!rfkill);
  464. spin_lock_irqsave(&rfkill->lock, flags);
  465. prev = !!(rfkill->state & RFKILL_BLOCK_SW);
  466. __rfkill_set_sw_state(rfkill, blocked);
  467. hwblock = !!(rfkill->state & RFKILL_BLOCK_HW);
  468. blocked = blocked || hwblock;
  469. spin_unlock_irqrestore(&rfkill->lock, flags);
  470. if (!rfkill->registered)
  471. return blocked;
  472. if (prev != blocked && !hwblock)
  473. schedule_work(&rfkill->uevent_work);
  474. rfkill_led_trigger_event(rfkill);
  475. rfkill_any_led_trigger_event();
  476. return blocked;
  477. }
  478. EXPORT_SYMBOL(rfkill_set_sw_state);
  479. void rfkill_init_sw_state(struct rfkill *rfkill, bool blocked)
  480. {
  481. unsigned long flags;
  482. BUG_ON(!rfkill);
  483. BUG_ON(rfkill->registered);
  484. spin_lock_irqsave(&rfkill->lock, flags);
  485. __rfkill_set_sw_state(rfkill, blocked);
  486. rfkill->persistent = true;
  487. spin_unlock_irqrestore(&rfkill->lock, flags);
  488. }
  489. EXPORT_SYMBOL(rfkill_init_sw_state);
  490. void rfkill_set_states(struct rfkill *rfkill, bool sw, bool hw)
  491. {
  492. unsigned long flags;
  493. bool swprev, hwprev;
  494. BUG_ON(!rfkill);
  495. spin_lock_irqsave(&rfkill->lock, flags);
  496. /*
  497. * No need to care about prev/setblock ... this is for uevent only
  498. * and that will get triggered by rfkill_set_block anyway.
  499. */
  500. swprev = !!(rfkill->state & RFKILL_BLOCK_SW);
  501. hwprev = !!(rfkill->state & RFKILL_BLOCK_HW);
  502. __rfkill_set_sw_state(rfkill, sw);
  503. if (hw)
  504. rfkill->state |= RFKILL_BLOCK_HW;
  505. else
  506. rfkill->state &= ~RFKILL_BLOCK_HW;
  507. spin_unlock_irqrestore(&rfkill->lock, flags);
  508. if (!rfkill->registered) {
  509. rfkill->persistent = true;
  510. } else {
  511. if (swprev != sw || hwprev != hw)
  512. schedule_work(&rfkill->uevent_work);
  513. rfkill_led_trigger_event(rfkill);
  514. rfkill_any_led_trigger_event();
  515. }
  516. }
  517. EXPORT_SYMBOL(rfkill_set_states);
  518. static const char * const rfkill_types[] = {
  519. NULL, /* RFKILL_TYPE_ALL */
  520. "wlan",
  521. "bluetooth",
  522. "ultrawideband",
  523. "wimax",
  524. "wwan",
  525. "gps",
  526. "fm",
  527. "nfc",
  528. };
  529. enum rfkill_type rfkill_find_type(const char *name)
  530. {
  531. int i;
  532. BUILD_BUG_ON(ARRAY_SIZE(rfkill_types) != NUM_RFKILL_TYPES);
  533. if (!name)
  534. return RFKILL_TYPE_ALL;
  535. for (i = 1; i < NUM_RFKILL_TYPES; i++)
  536. if (!strcmp(name, rfkill_types[i]))
  537. return i;
  538. return RFKILL_TYPE_ALL;
  539. }
  540. EXPORT_SYMBOL(rfkill_find_type);
  541. static ssize_t name_show(struct device *dev, struct device_attribute *attr,
  542. char *buf)
  543. {
  544. struct rfkill *rfkill = to_rfkill(dev);
  545. return sprintf(buf, "%s\n", rfkill->name);
  546. }
  547. static DEVICE_ATTR_RO(name);
  548. static ssize_t type_show(struct device *dev, struct device_attribute *attr,
  549. char *buf)
  550. {
  551. struct rfkill *rfkill = to_rfkill(dev);
  552. return sprintf(buf, "%s\n", rfkill_types[rfkill->type]);
  553. }
  554. static DEVICE_ATTR_RO(type);
  555. static ssize_t index_show(struct device *dev, struct device_attribute *attr,
  556. char *buf)
  557. {
  558. struct rfkill *rfkill = to_rfkill(dev);
  559. return sprintf(buf, "%d\n", rfkill->idx);
  560. }
  561. static DEVICE_ATTR_RO(index);
  562. static ssize_t persistent_show(struct device *dev,
  563. struct device_attribute *attr, char *buf)
  564. {
  565. struct rfkill *rfkill = to_rfkill(dev);
  566. return sprintf(buf, "%d\n", rfkill->persistent);
  567. }
  568. static DEVICE_ATTR_RO(persistent);
  569. static ssize_t hard_show(struct device *dev, struct device_attribute *attr,
  570. char *buf)
  571. {
  572. struct rfkill *rfkill = to_rfkill(dev);
  573. return sprintf(buf, "%d\n", (rfkill->state & RFKILL_BLOCK_HW) ? 1 : 0 );
  574. }
  575. static DEVICE_ATTR_RO(hard);
  576. static ssize_t soft_show(struct device *dev, struct device_attribute *attr,
  577. char *buf)
  578. {
  579. struct rfkill *rfkill = to_rfkill(dev);
  580. return sprintf(buf, "%d\n", (rfkill->state & RFKILL_BLOCK_SW) ? 1 : 0 );
  581. }
  582. static ssize_t soft_store(struct device *dev, struct device_attribute *attr,
  583. const char *buf, size_t count)
  584. {
  585. struct rfkill *rfkill = to_rfkill(dev);
  586. unsigned long state;
  587. int err;
  588. if (!capable(CAP_NET_ADMIN))
  589. return -EPERM;
  590. err = kstrtoul(buf, 0, &state);
  591. if (err)
  592. return err;
  593. if (state > 1 )
  594. return -EINVAL;
  595. mutex_lock(&rfkill_global_mutex);
  596. rfkill_set_block(rfkill, state);
  597. mutex_unlock(&rfkill_global_mutex);
  598. return count;
  599. }
  600. static DEVICE_ATTR_RW(soft);
  601. static u8 user_state_from_blocked(unsigned long state)
  602. {
  603. if (state & RFKILL_BLOCK_HW)
  604. return RFKILL_USER_STATE_HARD_BLOCKED;
  605. if (state & RFKILL_BLOCK_SW)
  606. return RFKILL_USER_STATE_SOFT_BLOCKED;
  607. return RFKILL_USER_STATE_UNBLOCKED;
  608. }
  609. static ssize_t state_show(struct device *dev, struct device_attribute *attr,
  610. char *buf)
  611. {
  612. struct rfkill *rfkill = to_rfkill(dev);
  613. return sprintf(buf, "%d\n", user_state_from_blocked(rfkill->state));
  614. }
  615. static ssize_t state_store(struct device *dev, struct device_attribute *attr,
  616. const char *buf, size_t count)
  617. {
  618. struct rfkill *rfkill = to_rfkill(dev);
  619. unsigned long state;
  620. int err;
  621. if (!capable(CAP_NET_ADMIN))
  622. return -EPERM;
  623. err = kstrtoul(buf, 0, &state);
  624. if (err)
  625. return err;
  626. if (state != RFKILL_USER_STATE_SOFT_BLOCKED &&
  627. state != RFKILL_USER_STATE_UNBLOCKED)
  628. return -EINVAL;
  629. mutex_lock(&rfkill_global_mutex);
  630. rfkill_set_block(rfkill, state == RFKILL_USER_STATE_SOFT_BLOCKED);
  631. mutex_unlock(&rfkill_global_mutex);
  632. return count;
  633. }
  634. static DEVICE_ATTR_RW(state);
  635. static struct attribute *rfkill_dev_attrs[] = {
  636. &dev_attr_name.attr,
  637. &dev_attr_type.attr,
  638. &dev_attr_index.attr,
  639. &dev_attr_persistent.attr,
  640. &dev_attr_state.attr,
  641. &dev_attr_soft.attr,
  642. &dev_attr_hard.attr,
  643. NULL,
  644. };
  645. ATTRIBUTE_GROUPS(rfkill_dev);
  646. static void rfkill_release(struct device *dev)
  647. {
  648. struct rfkill *rfkill = to_rfkill(dev);
  649. kfree(rfkill);
  650. }
  651. static int rfkill_dev_uevent(struct device *dev, struct kobj_uevent_env *env)
  652. {
  653. struct rfkill *rfkill = to_rfkill(dev);
  654. unsigned long flags;
  655. u32 state;
  656. int error;
  657. error = add_uevent_var(env, "RFKILL_NAME=%s", rfkill->name);
  658. if (error)
  659. return error;
  660. error = add_uevent_var(env, "RFKILL_TYPE=%s",
  661. rfkill_types[rfkill->type]);
  662. if (error)
  663. return error;
  664. spin_lock_irqsave(&rfkill->lock, flags);
  665. state = rfkill->state;
  666. spin_unlock_irqrestore(&rfkill->lock, flags);
  667. error = add_uevent_var(env, "RFKILL_STATE=%d",
  668. user_state_from_blocked(state));
  669. return error;
  670. }
  671. void rfkill_pause_polling(struct rfkill *rfkill)
  672. {
  673. BUG_ON(!rfkill);
  674. if (!rfkill->ops->poll)
  675. return;
  676. rfkill->polling_paused = true;
  677. cancel_delayed_work_sync(&rfkill->poll_work);
  678. }
  679. EXPORT_SYMBOL(rfkill_pause_polling);
  680. void rfkill_resume_polling(struct rfkill *rfkill)
  681. {
  682. BUG_ON(!rfkill);
  683. if (!rfkill->ops->poll)
  684. return;
  685. rfkill->polling_paused = false;
  686. if (rfkill->suspended)
  687. return;
  688. queue_delayed_work(system_power_efficient_wq,
  689. &rfkill->poll_work, 0);
  690. }
  691. EXPORT_SYMBOL(rfkill_resume_polling);
  692. #ifdef CONFIG_PM_SLEEP
  693. static int rfkill_suspend(struct device *dev)
  694. {
  695. struct rfkill *rfkill = to_rfkill(dev);
  696. rfkill->suspended = true;
  697. cancel_delayed_work_sync(&rfkill->poll_work);
  698. return 0;
  699. }
  700. static int rfkill_resume(struct device *dev)
  701. {
  702. struct rfkill *rfkill = to_rfkill(dev);
  703. bool cur;
  704. rfkill->suspended = false;
  705. if (!rfkill->persistent) {
  706. cur = !!(rfkill->state & RFKILL_BLOCK_SW);
  707. rfkill_set_block(rfkill, cur);
  708. }
  709. if (rfkill->ops->poll && !rfkill->polling_paused)
  710. queue_delayed_work(system_power_efficient_wq,
  711. &rfkill->poll_work, 0);
  712. return 0;
  713. }
  714. static SIMPLE_DEV_PM_OPS(rfkill_pm_ops, rfkill_suspend, rfkill_resume);
  715. #define RFKILL_PM_OPS (&rfkill_pm_ops)
  716. #else
  717. #define RFKILL_PM_OPS NULL
  718. #endif
  719. static struct class rfkill_class = {
  720. .name = "rfkill",
  721. .dev_release = rfkill_release,
  722. .dev_groups = rfkill_dev_groups,
  723. .dev_uevent = rfkill_dev_uevent,
  724. .pm = RFKILL_PM_OPS,
  725. };
  726. bool rfkill_blocked(struct rfkill *rfkill)
  727. {
  728. unsigned long flags;
  729. u32 state;
  730. spin_lock_irqsave(&rfkill->lock, flags);
  731. state = rfkill->state;
  732. spin_unlock_irqrestore(&rfkill->lock, flags);
  733. return !!(state & RFKILL_BLOCK_ANY);
  734. }
  735. EXPORT_SYMBOL(rfkill_blocked);
  736. struct rfkill * __must_check rfkill_alloc(const char *name,
  737. struct device *parent,
  738. const enum rfkill_type type,
  739. const struct rfkill_ops *ops,
  740. void *ops_data)
  741. {
  742. struct rfkill *rfkill;
  743. struct device *dev;
  744. if (WARN_ON(!ops))
  745. return NULL;
  746. if (WARN_ON(!ops->set_block))
  747. return NULL;
  748. if (WARN_ON(!name))
  749. return NULL;
  750. if (WARN_ON(type == RFKILL_TYPE_ALL || type >= NUM_RFKILL_TYPES))
  751. return NULL;
  752. rfkill = kzalloc(sizeof(*rfkill) + strlen(name) + 1, GFP_KERNEL);
  753. if (!rfkill)
  754. return NULL;
  755. spin_lock_init(&rfkill->lock);
  756. INIT_LIST_HEAD(&rfkill->node);
  757. rfkill->type = type;
  758. strcpy(rfkill->name, name);
  759. rfkill->ops = ops;
  760. rfkill->data = ops_data;
  761. dev = &rfkill->dev;
  762. dev->class = &rfkill_class;
  763. dev->parent = parent;
  764. device_initialize(dev);
  765. return rfkill;
  766. }
  767. EXPORT_SYMBOL(rfkill_alloc);
  768. static void rfkill_poll(struct work_struct *work)
  769. {
  770. struct rfkill *rfkill;
  771. rfkill = container_of(work, struct rfkill, poll_work.work);
  772. /*
  773. * Poll hardware state -- driver will use one of the
  774. * rfkill_set{,_hw,_sw}_state functions and use its
  775. * return value to update the current status.
  776. */
  777. rfkill->ops->poll(rfkill, rfkill->data);
  778. queue_delayed_work(system_power_efficient_wq,
  779. &rfkill->poll_work,
  780. round_jiffies_relative(POLL_INTERVAL));
  781. }
  782. static void rfkill_uevent_work(struct work_struct *work)
  783. {
  784. struct rfkill *rfkill;
  785. rfkill = container_of(work, struct rfkill, uevent_work);
  786. mutex_lock(&rfkill_global_mutex);
  787. rfkill_event(rfkill);
  788. mutex_unlock(&rfkill_global_mutex);
  789. }
  790. static void rfkill_sync_work(struct work_struct *work)
  791. {
  792. struct rfkill *rfkill;
  793. bool cur;
  794. rfkill = container_of(work, struct rfkill, sync_work);
  795. mutex_lock(&rfkill_global_mutex);
  796. cur = rfkill_global_states[rfkill->type].cur;
  797. rfkill_set_block(rfkill, cur);
  798. mutex_unlock(&rfkill_global_mutex);
  799. }
  800. int __must_check rfkill_register(struct rfkill *rfkill)
  801. {
  802. static unsigned long rfkill_no;
  803. struct device *dev = &rfkill->dev;
  804. int error;
  805. BUG_ON(!rfkill);
  806. mutex_lock(&rfkill_global_mutex);
  807. if (rfkill->registered) {
  808. error = -EALREADY;
  809. goto unlock;
  810. }
  811. rfkill->idx = rfkill_no;
  812. dev_set_name(dev, "rfkill%lu", rfkill_no);
  813. rfkill_no++;
  814. list_add_tail(&rfkill->node, &rfkill_list);
  815. error = device_add(dev);
  816. if (error)
  817. goto remove;
  818. error = rfkill_led_trigger_register(rfkill);
  819. if (error)
  820. goto devdel;
  821. rfkill->registered = true;
  822. INIT_DELAYED_WORK(&rfkill->poll_work, rfkill_poll);
  823. INIT_WORK(&rfkill->uevent_work, rfkill_uevent_work);
  824. INIT_WORK(&rfkill->sync_work, rfkill_sync_work);
  825. if (rfkill->ops->poll)
  826. queue_delayed_work(system_power_efficient_wq,
  827. &rfkill->poll_work,
  828. round_jiffies_relative(POLL_INTERVAL));
  829. if (!rfkill->persistent || rfkill_epo_lock_active) {
  830. schedule_work(&rfkill->sync_work);
  831. } else {
  832. #ifdef CONFIG_RFKILL_INPUT
  833. bool soft_blocked = !!(rfkill->state & RFKILL_BLOCK_SW);
  834. if (!atomic_read(&rfkill_input_disabled))
  835. __rfkill_switch_all(rfkill->type, soft_blocked);
  836. #endif
  837. }
  838. rfkill_any_led_trigger_event();
  839. rfkill_send_events(rfkill, RFKILL_OP_ADD);
  840. mutex_unlock(&rfkill_global_mutex);
  841. return 0;
  842. devdel:
  843. device_del(&rfkill->dev);
  844. remove:
  845. list_del_init(&rfkill->node);
  846. unlock:
  847. mutex_unlock(&rfkill_global_mutex);
  848. return error;
  849. }
  850. EXPORT_SYMBOL(rfkill_register);
  851. void rfkill_unregister(struct rfkill *rfkill)
  852. {
  853. BUG_ON(!rfkill);
  854. if (rfkill->ops->poll)
  855. cancel_delayed_work_sync(&rfkill->poll_work);
  856. cancel_work_sync(&rfkill->uevent_work);
  857. cancel_work_sync(&rfkill->sync_work);
  858. rfkill->registered = false;
  859. device_del(&rfkill->dev);
  860. mutex_lock(&rfkill_global_mutex);
  861. rfkill_send_events(rfkill, RFKILL_OP_DEL);
  862. list_del_init(&rfkill->node);
  863. rfkill_any_led_trigger_event();
  864. mutex_unlock(&rfkill_global_mutex);
  865. rfkill_led_trigger_unregister(rfkill);
  866. }
  867. EXPORT_SYMBOL(rfkill_unregister);
  868. void rfkill_destroy(struct rfkill *rfkill)
  869. {
  870. if (rfkill)
  871. put_device(&rfkill->dev);
  872. }
  873. EXPORT_SYMBOL(rfkill_destroy);
  874. static int rfkill_fop_open(struct inode *inode, struct file *file)
  875. {
  876. struct rfkill_data *data;
  877. struct rfkill *rfkill;
  878. struct rfkill_int_event *ev, *tmp;
  879. data = kzalloc(sizeof(*data), GFP_KERNEL);
  880. if (!data)
  881. return -ENOMEM;
  882. INIT_LIST_HEAD(&data->events);
  883. mutex_init(&data->mtx);
  884. init_waitqueue_head(&data->read_wait);
  885. mutex_lock(&rfkill_global_mutex);
  886. mutex_lock(&data->mtx);
  887. /*
  888. * start getting events from elsewhere but hold mtx to get
  889. * startup events added first
  890. */
  891. list_for_each_entry(rfkill, &rfkill_list, node) {
  892. ev = kzalloc(sizeof(*ev), GFP_KERNEL);
  893. if (!ev)
  894. goto free;
  895. rfkill_fill_event(&ev->ev, rfkill, RFKILL_OP_ADD);
  896. list_add_tail(&ev->list, &data->events);
  897. }
  898. list_add(&data->list, &rfkill_fds);
  899. mutex_unlock(&data->mtx);
  900. mutex_unlock(&rfkill_global_mutex);
  901. file->private_data = data;
  902. return nonseekable_open(inode, file);
  903. free:
  904. mutex_unlock(&data->mtx);
  905. mutex_unlock(&rfkill_global_mutex);
  906. mutex_destroy(&data->mtx);
  907. list_for_each_entry_safe(ev, tmp, &data->events, list)
  908. kfree(ev);
  909. kfree(data);
  910. return -ENOMEM;
  911. }
  912. static unsigned int rfkill_fop_poll(struct file *file, poll_table *wait)
  913. {
  914. struct rfkill_data *data = file->private_data;
  915. unsigned int res = POLLOUT | POLLWRNORM;
  916. poll_wait(file, &data->read_wait, wait);
  917. mutex_lock(&data->mtx);
  918. if (!list_empty(&data->events))
  919. res = POLLIN | POLLRDNORM;
  920. mutex_unlock(&data->mtx);
  921. return res;
  922. }
  923. static ssize_t rfkill_fop_read(struct file *file, char __user *buf,
  924. size_t count, loff_t *pos)
  925. {
  926. struct rfkill_data *data = file->private_data;
  927. struct rfkill_int_event *ev;
  928. unsigned long sz;
  929. int ret;
  930. mutex_lock(&data->mtx);
  931. while (list_empty(&data->events)) {
  932. if (file->f_flags & O_NONBLOCK) {
  933. ret = -EAGAIN;
  934. goto out;
  935. }
  936. mutex_unlock(&data->mtx);
  937. /* since we re-check and it just compares pointers,
  938. * using !list_empty() without locking isn't a problem
  939. */
  940. ret = wait_event_interruptible(data->read_wait,
  941. !list_empty(&data->events));
  942. mutex_lock(&data->mtx);
  943. if (ret)
  944. goto out;
  945. }
  946. ev = list_first_entry(&data->events, struct rfkill_int_event,
  947. list);
  948. sz = min_t(unsigned long, sizeof(ev->ev), count);
  949. ret = sz;
  950. if (copy_to_user(buf, &ev->ev, sz))
  951. ret = -EFAULT;
  952. list_del(&ev->list);
  953. kfree(ev);
  954. out:
  955. mutex_unlock(&data->mtx);
  956. return ret;
  957. }
  958. static ssize_t rfkill_fop_write(struct file *file, const char __user *buf,
  959. size_t count, loff_t *pos)
  960. {
  961. struct rfkill *rfkill;
  962. struct rfkill_event ev;
  963. int ret;
  964. /* we don't need the 'hard' variable but accept it */
  965. if (count < RFKILL_EVENT_SIZE_V1 - 1)
  966. return -EINVAL;
  967. /*
  968. * Copy as much data as we can accept into our 'ev' buffer,
  969. * but tell userspace how much we've copied so it can determine
  970. * our API version even in a write() call, if it cares.
  971. */
  972. count = min(count, sizeof(ev));
  973. if (copy_from_user(&ev, buf, count))
  974. return -EFAULT;
  975. if (ev.type >= NUM_RFKILL_TYPES)
  976. return -EINVAL;
  977. mutex_lock(&rfkill_global_mutex);
  978. switch (ev.op) {
  979. case RFKILL_OP_CHANGE_ALL:
  980. rfkill_update_global_state(ev.type, ev.soft);
  981. list_for_each_entry(rfkill, &rfkill_list, node)
  982. if (rfkill->type == ev.type ||
  983. ev.type == RFKILL_TYPE_ALL)
  984. rfkill_set_block(rfkill, ev.soft);
  985. ret = 0;
  986. break;
  987. case RFKILL_OP_CHANGE:
  988. list_for_each_entry(rfkill, &rfkill_list, node)
  989. if (rfkill->idx == ev.idx &&
  990. (rfkill->type == ev.type ||
  991. ev.type == RFKILL_TYPE_ALL))
  992. rfkill_set_block(rfkill, ev.soft);
  993. ret = 0;
  994. break;
  995. default:
  996. ret = -EINVAL;
  997. break;
  998. }
  999. mutex_unlock(&rfkill_global_mutex);
  1000. return ret ?: count;
  1001. }
  1002. static int rfkill_fop_release(struct inode *inode, struct file *file)
  1003. {
  1004. struct rfkill_data *data = file->private_data;
  1005. struct rfkill_int_event *ev, *tmp;
  1006. mutex_lock(&rfkill_global_mutex);
  1007. list_del(&data->list);
  1008. mutex_unlock(&rfkill_global_mutex);
  1009. mutex_destroy(&data->mtx);
  1010. list_for_each_entry_safe(ev, tmp, &data->events, list)
  1011. kfree(ev);
  1012. #ifdef CONFIG_RFKILL_INPUT
  1013. if (data->input_handler)
  1014. if (atomic_dec_return(&rfkill_input_disabled) == 0)
  1015. printk(KERN_DEBUG "rfkill: input handler enabled\n");
  1016. #endif
  1017. kfree(data);
  1018. return 0;
  1019. }
  1020. #ifdef CONFIG_RFKILL_INPUT
  1021. static long rfkill_fop_ioctl(struct file *file, unsigned int cmd,
  1022. unsigned long arg)
  1023. {
  1024. struct rfkill_data *data = file->private_data;
  1025. if (_IOC_TYPE(cmd) != RFKILL_IOC_MAGIC)
  1026. return -ENOSYS;
  1027. if (_IOC_NR(cmd) != RFKILL_IOC_NOINPUT)
  1028. return -ENOSYS;
  1029. mutex_lock(&data->mtx);
  1030. if (!data->input_handler) {
  1031. if (atomic_inc_return(&rfkill_input_disabled) == 1)
  1032. printk(KERN_DEBUG "rfkill: input handler disabled\n");
  1033. data->input_handler = true;
  1034. }
  1035. mutex_unlock(&data->mtx);
  1036. return 0;
  1037. }
  1038. #endif
  1039. static const struct file_operations rfkill_fops = {
  1040. .owner = THIS_MODULE,
  1041. .open = rfkill_fop_open,
  1042. .read = rfkill_fop_read,
  1043. .write = rfkill_fop_write,
  1044. .poll = rfkill_fop_poll,
  1045. .release = rfkill_fop_release,
  1046. #ifdef CONFIG_RFKILL_INPUT
  1047. .unlocked_ioctl = rfkill_fop_ioctl,
  1048. .compat_ioctl = rfkill_fop_ioctl,
  1049. #endif
  1050. .llseek = no_llseek,
  1051. };
  1052. static struct miscdevice rfkill_miscdev = {
  1053. .name = "rfkill",
  1054. .fops = &rfkill_fops,
  1055. .minor = MISC_DYNAMIC_MINOR,
  1056. };
  1057. static int __init rfkill_init(void)
  1058. {
  1059. int error;
  1060. rfkill_update_global_state(RFKILL_TYPE_ALL, !rfkill_default_state);
  1061. error = class_register(&rfkill_class);
  1062. if (error)
  1063. goto error_class;
  1064. error = misc_register(&rfkill_miscdev);
  1065. if (error)
  1066. goto error_misc;
  1067. error = rfkill_any_led_trigger_register();
  1068. if (error)
  1069. goto error_led_trigger;
  1070. #ifdef CONFIG_RFKILL_INPUT
  1071. error = rfkill_handler_init();
  1072. if (error)
  1073. goto error_input;
  1074. #endif
  1075. return 0;
  1076. #ifdef CONFIG_RFKILL_INPUT
  1077. error_input:
  1078. rfkill_any_led_trigger_unregister();
  1079. #endif
  1080. error_led_trigger:
  1081. misc_deregister(&rfkill_miscdev);
  1082. error_misc:
  1083. class_unregister(&rfkill_class);
  1084. error_class:
  1085. return error;
  1086. }
  1087. subsys_initcall(rfkill_init);
  1088. static void __exit rfkill_exit(void)
  1089. {
  1090. #ifdef CONFIG_RFKILL_INPUT
  1091. rfkill_handler_exit();
  1092. #endif
  1093. rfkill_any_led_trigger_unregister();
  1094. misc_deregister(&rfkill_miscdev);
  1095. class_unregister(&rfkill_class);
  1096. }
  1097. module_exit(rfkill_exit);