core.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373
  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. static __maybe_unused int rfkill_suspend(struct device *dev)
  693. {
  694. struct rfkill *rfkill = to_rfkill(dev);
  695. rfkill->suspended = true;
  696. cancel_delayed_work_sync(&rfkill->poll_work);
  697. return 0;
  698. }
  699. static __maybe_unused int rfkill_resume(struct device *dev)
  700. {
  701. struct rfkill *rfkill = to_rfkill(dev);
  702. bool cur;
  703. rfkill->suspended = false;
  704. if (!rfkill->persistent) {
  705. cur = !!(rfkill->state & RFKILL_BLOCK_SW);
  706. rfkill_set_block(rfkill, cur);
  707. }
  708. if (rfkill->ops->poll && !rfkill->polling_paused)
  709. queue_delayed_work(system_power_efficient_wq,
  710. &rfkill->poll_work, 0);
  711. return 0;
  712. }
  713. static SIMPLE_DEV_PM_OPS(rfkill_pm_ops, rfkill_suspend, rfkill_resume);
  714. static struct class rfkill_class = {
  715. .name = "rfkill",
  716. .dev_release = rfkill_release,
  717. .dev_groups = rfkill_dev_groups,
  718. .dev_uevent = rfkill_dev_uevent,
  719. .pm = IS_ENABLED(CONFIG_RFKILL_PM) ? &rfkill_pm_ops : NULL,
  720. };
  721. bool rfkill_blocked(struct rfkill *rfkill)
  722. {
  723. unsigned long flags;
  724. u32 state;
  725. spin_lock_irqsave(&rfkill->lock, flags);
  726. state = rfkill->state;
  727. spin_unlock_irqrestore(&rfkill->lock, flags);
  728. return !!(state & RFKILL_BLOCK_ANY);
  729. }
  730. EXPORT_SYMBOL(rfkill_blocked);
  731. struct rfkill * __must_check rfkill_alloc(const char *name,
  732. struct device *parent,
  733. const enum rfkill_type type,
  734. const struct rfkill_ops *ops,
  735. void *ops_data)
  736. {
  737. struct rfkill *rfkill;
  738. struct device *dev;
  739. if (WARN_ON(!ops))
  740. return NULL;
  741. if (WARN_ON(!ops->set_block))
  742. return NULL;
  743. if (WARN_ON(!name))
  744. return NULL;
  745. if (WARN_ON(type == RFKILL_TYPE_ALL || type >= NUM_RFKILL_TYPES))
  746. return NULL;
  747. rfkill = kzalloc(sizeof(*rfkill) + strlen(name) + 1, GFP_KERNEL);
  748. if (!rfkill)
  749. return NULL;
  750. spin_lock_init(&rfkill->lock);
  751. INIT_LIST_HEAD(&rfkill->node);
  752. rfkill->type = type;
  753. strcpy(rfkill->name, name);
  754. rfkill->ops = ops;
  755. rfkill->data = ops_data;
  756. dev = &rfkill->dev;
  757. dev->class = &rfkill_class;
  758. dev->parent = parent;
  759. device_initialize(dev);
  760. return rfkill;
  761. }
  762. EXPORT_SYMBOL(rfkill_alloc);
  763. static void rfkill_poll(struct work_struct *work)
  764. {
  765. struct rfkill *rfkill;
  766. rfkill = container_of(work, struct rfkill, poll_work.work);
  767. /*
  768. * Poll hardware state -- driver will use one of the
  769. * rfkill_set{,_hw,_sw}_state functions and use its
  770. * return value to update the current status.
  771. */
  772. rfkill->ops->poll(rfkill, rfkill->data);
  773. queue_delayed_work(system_power_efficient_wq,
  774. &rfkill->poll_work,
  775. round_jiffies_relative(POLL_INTERVAL));
  776. }
  777. static void rfkill_uevent_work(struct work_struct *work)
  778. {
  779. struct rfkill *rfkill;
  780. rfkill = container_of(work, struct rfkill, uevent_work);
  781. mutex_lock(&rfkill_global_mutex);
  782. rfkill_event(rfkill);
  783. mutex_unlock(&rfkill_global_mutex);
  784. }
  785. static void rfkill_sync_work(struct work_struct *work)
  786. {
  787. struct rfkill *rfkill;
  788. bool cur;
  789. rfkill = container_of(work, struct rfkill, sync_work);
  790. mutex_lock(&rfkill_global_mutex);
  791. cur = rfkill_global_states[rfkill->type].cur;
  792. rfkill_set_block(rfkill, cur);
  793. mutex_unlock(&rfkill_global_mutex);
  794. }
  795. int __must_check rfkill_register(struct rfkill *rfkill)
  796. {
  797. static unsigned long rfkill_no;
  798. struct device *dev;
  799. int error;
  800. if (!rfkill)
  801. return -EINVAL;
  802. dev = &rfkill->dev;
  803. mutex_lock(&rfkill_global_mutex);
  804. if (rfkill->registered) {
  805. error = -EALREADY;
  806. goto unlock;
  807. }
  808. rfkill->idx = rfkill_no;
  809. dev_set_name(dev, "rfkill%lu", rfkill_no);
  810. rfkill_no++;
  811. list_add_tail(&rfkill->node, &rfkill_list);
  812. error = device_add(dev);
  813. if (error)
  814. goto remove;
  815. error = rfkill_led_trigger_register(rfkill);
  816. if (error)
  817. goto devdel;
  818. rfkill->registered = true;
  819. INIT_DELAYED_WORK(&rfkill->poll_work, rfkill_poll);
  820. INIT_WORK(&rfkill->uevent_work, rfkill_uevent_work);
  821. INIT_WORK(&rfkill->sync_work, rfkill_sync_work);
  822. if (rfkill->ops->poll)
  823. queue_delayed_work(system_power_efficient_wq,
  824. &rfkill->poll_work,
  825. round_jiffies_relative(POLL_INTERVAL));
  826. if (!rfkill->persistent || rfkill_epo_lock_active) {
  827. schedule_work(&rfkill->sync_work);
  828. } else {
  829. #ifdef CONFIG_RFKILL_INPUT
  830. bool soft_blocked = !!(rfkill->state & RFKILL_BLOCK_SW);
  831. if (!atomic_read(&rfkill_input_disabled))
  832. __rfkill_switch_all(rfkill->type, soft_blocked);
  833. #endif
  834. }
  835. rfkill_any_led_trigger_event();
  836. rfkill_send_events(rfkill, RFKILL_OP_ADD);
  837. mutex_unlock(&rfkill_global_mutex);
  838. return 0;
  839. devdel:
  840. device_del(&rfkill->dev);
  841. remove:
  842. list_del_init(&rfkill->node);
  843. unlock:
  844. mutex_unlock(&rfkill_global_mutex);
  845. return error;
  846. }
  847. EXPORT_SYMBOL(rfkill_register);
  848. void rfkill_unregister(struct rfkill *rfkill)
  849. {
  850. BUG_ON(!rfkill);
  851. if (rfkill->ops->poll)
  852. cancel_delayed_work_sync(&rfkill->poll_work);
  853. cancel_work_sync(&rfkill->uevent_work);
  854. cancel_work_sync(&rfkill->sync_work);
  855. rfkill->registered = false;
  856. device_del(&rfkill->dev);
  857. mutex_lock(&rfkill_global_mutex);
  858. rfkill_send_events(rfkill, RFKILL_OP_DEL);
  859. list_del_init(&rfkill->node);
  860. rfkill_any_led_trigger_event();
  861. mutex_unlock(&rfkill_global_mutex);
  862. rfkill_led_trigger_unregister(rfkill);
  863. }
  864. EXPORT_SYMBOL(rfkill_unregister);
  865. void rfkill_destroy(struct rfkill *rfkill)
  866. {
  867. if (rfkill)
  868. put_device(&rfkill->dev);
  869. }
  870. EXPORT_SYMBOL(rfkill_destroy);
  871. static int rfkill_fop_open(struct inode *inode, struct file *file)
  872. {
  873. struct rfkill_data *data;
  874. struct rfkill *rfkill;
  875. struct rfkill_int_event *ev, *tmp;
  876. data = kzalloc(sizeof(*data), GFP_KERNEL);
  877. if (!data)
  878. return -ENOMEM;
  879. INIT_LIST_HEAD(&data->events);
  880. mutex_init(&data->mtx);
  881. init_waitqueue_head(&data->read_wait);
  882. mutex_lock(&rfkill_global_mutex);
  883. mutex_lock(&data->mtx);
  884. /*
  885. * start getting events from elsewhere but hold mtx to get
  886. * startup events added first
  887. */
  888. list_for_each_entry(rfkill, &rfkill_list, node) {
  889. ev = kzalloc(sizeof(*ev), GFP_KERNEL);
  890. if (!ev)
  891. goto free;
  892. rfkill_fill_event(&ev->ev, rfkill, RFKILL_OP_ADD);
  893. list_add_tail(&ev->list, &data->events);
  894. }
  895. list_add(&data->list, &rfkill_fds);
  896. mutex_unlock(&data->mtx);
  897. mutex_unlock(&rfkill_global_mutex);
  898. file->private_data = data;
  899. return nonseekable_open(inode, file);
  900. free:
  901. mutex_unlock(&data->mtx);
  902. mutex_unlock(&rfkill_global_mutex);
  903. mutex_destroy(&data->mtx);
  904. list_for_each_entry_safe(ev, tmp, &data->events, list)
  905. kfree(ev);
  906. kfree(data);
  907. return -ENOMEM;
  908. }
  909. static unsigned int rfkill_fop_poll(struct file *file, poll_table *wait)
  910. {
  911. struct rfkill_data *data = file->private_data;
  912. unsigned int res = POLLOUT | POLLWRNORM;
  913. poll_wait(file, &data->read_wait, wait);
  914. mutex_lock(&data->mtx);
  915. if (!list_empty(&data->events))
  916. res = POLLIN | POLLRDNORM;
  917. mutex_unlock(&data->mtx);
  918. return res;
  919. }
  920. static ssize_t rfkill_fop_read(struct file *file, char __user *buf,
  921. size_t count, loff_t *pos)
  922. {
  923. struct rfkill_data *data = file->private_data;
  924. struct rfkill_int_event *ev;
  925. unsigned long sz;
  926. int ret;
  927. mutex_lock(&data->mtx);
  928. while (list_empty(&data->events)) {
  929. if (file->f_flags & O_NONBLOCK) {
  930. ret = -EAGAIN;
  931. goto out;
  932. }
  933. mutex_unlock(&data->mtx);
  934. /* since we re-check and it just compares pointers,
  935. * using !list_empty() without locking isn't a problem
  936. */
  937. ret = wait_event_interruptible(data->read_wait,
  938. !list_empty(&data->events));
  939. mutex_lock(&data->mtx);
  940. if (ret)
  941. goto out;
  942. }
  943. ev = list_first_entry(&data->events, struct rfkill_int_event,
  944. list);
  945. sz = min_t(unsigned long, sizeof(ev->ev), count);
  946. ret = sz;
  947. if (copy_to_user(buf, &ev->ev, sz))
  948. ret = -EFAULT;
  949. list_del(&ev->list);
  950. kfree(ev);
  951. out:
  952. mutex_unlock(&data->mtx);
  953. return ret;
  954. }
  955. static ssize_t rfkill_fop_write(struct file *file, const char __user *buf,
  956. size_t count, loff_t *pos)
  957. {
  958. struct rfkill *rfkill;
  959. struct rfkill_event ev;
  960. int ret;
  961. /* we don't need the 'hard' variable but accept it */
  962. if (count < RFKILL_EVENT_SIZE_V1 - 1)
  963. return -EINVAL;
  964. /*
  965. * Copy as much data as we can accept into our 'ev' buffer,
  966. * but tell userspace how much we've copied so it can determine
  967. * our API version even in a write() call, if it cares.
  968. */
  969. count = min(count, sizeof(ev));
  970. if (copy_from_user(&ev, buf, count))
  971. return -EFAULT;
  972. if (ev.type >= NUM_RFKILL_TYPES)
  973. return -EINVAL;
  974. mutex_lock(&rfkill_global_mutex);
  975. switch (ev.op) {
  976. case RFKILL_OP_CHANGE_ALL:
  977. rfkill_update_global_state(ev.type, ev.soft);
  978. list_for_each_entry(rfkill, &rfkill_list, node)
  979. if (rfkill->type == ev.type ||
  980. ev.type == RFKILL_TYPE_ALL)
  981. rfkill_set_block(rfkill, ev.soft);
  982. ret = 0;
  983. break;
  984. case RFKILL_OP_CHANGE:
  985. list_for_each_entry(rfkill, &rfkill_list, node)
  986. if (rfkill->idx == ev.idx &&
  987. (rfkill->type == ev.type ||
  988. ev.type == RFKILL_TYPE_ALL))
  989. rfkill_set_block(rfkill, ev.soft);
  990. ret = 0;
  991. break;
  992. default:
  993. ret = -EINVAL;
  994. break;
  995. }
  996. mutex_unlock(&rfkill_global_mutex);
  997. return ret ?: count;
  998. }
  999. static int rfkill_fop_release(struct inode *inode, struct file *file)
  1000. {
  1001. struct rfkill_data *data = file->private_data;
  1002. struct rfkill_int_event *ev, *tmp;
  1003. mutex_lock(&rfkill_global_mutex);
  1004. list_del(&data->list);
  1005. mutex_unlock(&rfkill_global_mutex);
  1006. mutex_destroy(&data->mtx);
  1007. list_for_each_entry_safe(ev, tmp, &data->events, list)
  1008. kfree(ev);
  1009. #ifdef CONFIG_RFKILL_INPUT
  1010. if (data->input_handler)
  1011. if (atomic_dec_return(&rfkill_input_disabled) == 0)
  1012. printk(KERN_DEBUG "rfkill: input handler enabled\n");
  1013. #endif
  1014. kfree(data);
  1015. return 0;
  1016. }
  1017. #ifdef CONFIG_RFKILL_INPUT
  1018. static long rfkill_fop_ioctl(struct file *file, unsigned int cmd,
  1019. unsigned long arg)
  1020. {
  1021. struct rfkill_data *data = file->private_data;
  1022. if (_IOC_TYPE(cmd) != RFKILL_IOC_MAGIC)
  1023. return -ENOSYS;
  1024. if (_IOC_NR(cmd) != RFKILL_IOC_NOINPUT)
  1025. return -ENOSYS;
  1026. mutex_lock(&data->mtx);
  1027. if (!data->input_handler) {
  1028. if (atomic_inc_return(&rfkill_input_disabled) == 1)
  1029. printk(KERN_DEBUG "rfkill: input handler disabled\n");
  1030. data->input_handler = true;
  1031. }
  1032. mutex_unlock(&data->mtx);
  1033. return 0;
  1034. }
  1035. #endif
  1036. static const struct file_operations rfkill_fops = {
  1037. .owner = THIS_MODULE,
  1038. .open = rfkill_fop_open,
  1039. .read = rfkill_fop_read,
  1040. .write = rfkill_fop_write,
  1041. .poll = rfkill_fop_poll,
  1042. .release = rfkill_fop_release,
  1043. #ifdef CONFIG_RFKILL_INPUT
  1044. .unlocked_ioctl = rfkill_fop_ioctl,
  1045. .compat_ioctl = rfkill_fop_ioctl,
  1046. #endif
  1047. .llseek = no_llseek,
  1048. };
  1049. #define RFKILL_NAME "rfkill"
  1050. static struct miscdevice rfkill_miscdev = {
  1051. .fops = &rfkill_fops,
  1052. .name = RFKILL_NAME,
  1053. .minor = RFKILL_MINOR,
  1054. };
  1055. static int __init rfkill_init(void)
  1056. {
  1057. int error;
  1058. rfkill_update_global_state(RFKILL_TYPE_ALL, !rfkill_default_state);
  1059. error = class_register(&rfkill_class);
  1060. if (error)
  1061. goto error_class;
  1062. error = misc_register(&rfkill_miscdev);
  1063. if (error)
  1064. goto error_misc;
  1065. error = rfkill_any_led_trigger_register();
  1066. if (error)
  1067. goto error_led_trigger;
  1068. #ifdef CONFIG_RFKILL_INPUT
  1069. error = rfkill_handler_init();
  1070. if (error)
  1071. goto error_input;
  1072. #endif
  1073. return 0;
  1074. #ifdef CONFIG_RFKILL_INPUT
  1075. error_input:
  1076. rfkill_any_led_trigger_unregister();
  1077. #endif
  1078. error_led_trigger:
  1079. misc_deregister(&rfkill_miscdev);
  1080. error_misc:
  1081. class_unregister(&rfkill_class);
  1082. error_class:
  1083. return error;
  1084. }
  1085. subsys_initcall(rfkill_init);
  1086. static void __exit rfkill_exit(void)
  1087. {
  1088. #ifdef CONFIG_RFKILL_INPUT
  1089. rfkill_handler_exit();
  1090. #endif
  1091. rfkill_any_led_trigger_unregister();
  1092. misc_deregister(&rfkill_miscdev);
  1093. class_unregister(&rfkill_class);
  1094. }
  1095. module_exit(rfkill_exit);
  1096. MODULE_ALIAS_MISCDEV(RFKILL_MINOR);
  1097. MODULE_ALIAS("devname:" RFKILL_NAME);