Loading...
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Input layer to RF Kill interface connector
4 *
5 * Copyright (c) 2007 Dmitry Torokhov
6 * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
7 *
8 * If you ever run into a situation in which you have a SW_ type rfkill
9 * input device, then you can revive code that was removed in the patch
10 * "rfkill-input: remove unused code".
11 */
12
13#include <linux/input.h>
14#include <linux/slab.h>
15#include <linux/moduleparam.h>
16#include <linux/workqueue.h>
17#include <linux/init.h>
18#include <linux/rfkill.h>
19#include <linux/sched.h>
20
21#include "rfkill.h"
22
23enum rfkill_input_master_mode {
24 RFKILL_INPUT_MASTER_UNLOCK = 0,
25 RFKILL_INPUT_MASTER_RESTORE = 1,
26 RFKILL_INPUT_MASTER_UNBLOCKALL = 2,
27 NUM_RFKILL_INPUT_MASTER_MODES
28};
29
30/* Delay (in ms) between consecutive switch ops */
31#define RFKILL_OPS_DELAY 200
32
33static enum rfkill_input_master_mode rfkill_master_switch_mode =
34 RFKILL_INPUT_MASTER_UNBLOCKALL;
35module_param_named(master_switch_mode, rfkill_master_switch_mode, uint, 0);
36MODULE_PARM_DESC(master_switch_mode,
37 "SW_RFKILL_ALL ON should: 0=do nothing (only unlock); 1=restore; 2=unblock all");
38
39static spinlock_t rfkill_op_lock;
40static bool rfkill_op_pending;
41static unsigned long rfkill_sw_pending[BITS_TO_LONGS(NUM_RFKILL_TYPES)];
42static unsigned long rfkill_sw_state[BITS_TO_LONGS(NUM_RFKILL_TYPES)];
43
44enum rfkill_sched_op {
45 RFKILL_GLOBAL_OP_EPO = 0,
46 RFKILL_GLOBAL_OP_RESTORE,
47 RFKILL_GLOBAL_OP_UNLOCK,
48 RFKILL_GLOBAL_OP_UNBLOCK,
49};
50
51static enum rfkill_sched_op rfkill_master_switch_op;
52static enum rfkill_sched_op rfkill_op;
53
54static void __rfkill_handle_global_op(enum rfkill_sched_op op)
55{
56 unsigned int i;
57
58 switch (op) {
59 case RFKILL_GLOBAL_OP_EPO:
60 rfkill_epo();
61 break;
62 case RFKILL_GLOBAL_OP_RESTORE:
63 rfkill_restore_states();
64 break;
65 case RFKILL_GLOBAL_OP_UNLOCK:
66 rfkill_remove_epo_lock();
67 break;
68 case RFKILL_GLOBAL_OP_UNBLOCK:
69 rfkill_remove_epo_lock();
70 for (i = 0; i < NUM_RFKILL_TYPES; i++)
71 rfkill_switch_all(i, false);
72 break;
73 default:
74 /* memory corruption or bug, fail safely */
75 rfkill_epo();
76 WARN(1, "Unknown requested operation %d! "
77 "rfkill Emergency Power Off activated\n",
78 op);
79 }
80}
81
82static void __rfkill_handle_normal_op(const enum rfkill_type type,
83 const bool complement)
84{
85 bool blocked;
86
87 blocked = rfkill_get_global_sw_state(type);
88 if (complement)
89 blocked = !blocked;
90
91 rfkill_switch_all(type, blocked);
92}
93
94static void rfkill_op_handler(struct work_struct *work)
95{
96 unsigned int i;
97 bool c;
98
99 spin_lock_irq(&rfkill_op_lock);
100 do {
101 if (rfkill_op_pending) {
102 enum rfkill_sched_op op = rfkill_op;
103 rfkill_op_pending = false;
104 memset(rfkill_sw_pending, 0,
105 sizeof(rfkill_sw_pending));
106 spin_unlock_irq(&rfkill_op_lock);
107
108 __rfkill_handle_global_op(op);
109
110 spin_lock_irq(&rfkill_op_lock);
111
112 /*
113 * handle global ops first -- during unlocked period
114 * we might have gotten a new global op.
115 */
116 if (rfkill_op_pending)
117 continue;
118 }
119
120 if (rfkill_is_epo_lock_active())
121 continue;
122
123 for (i = 0; i < NUM_RFKILL_TYPES; i++) {
124 if (__test_and_clear_bit(i, rfkill_sw_pending)) {
125 c = __test_and_clear_bit(i, rfkill_sw_state);
126 spin_unlock_irq(&rfkill_op_lock);
127
128 __rfkill_handle_normal_op(i, c);
129
130 spin_lock_irq(&rfkill_op_lock);
131 }
132 }
133 } while (rfkill_op_pending);
134 spin_unlock_irq(&rfkill_op_lock);
135}
136
137static DECLARE_DELAYED_WORK(rfkill_op_work, rfkill_op_handler);
138static unsigned long rfkill_last_scheduled;
139
140static unsigned long rfkill_ratelimit(const unsigned long last)
141{
142 const unsigned long delay = msecs_to_jiffies(RFKILL_OPS_DELAY);
143 return time_after(jiffies, last + delay) ? 0 : delay;
144}
145
146static void rfkill_schedule_ratelimited(void)
147{
148 if (schedule_delayed_work(&rfkill_op_work,
149 rfkill_ratelimit(rfkill_last_scheduled)))
150 rfkill_last_scheduled = jiffies;
151}
152
153static void rfkill_schedule_global_op(enum rfkill_sched_op op)
154{
155 unsigned long flags;
156
157 spin_lock_irqsave(&rfkill_op_lock, flags);
158 rfkill_op = op;
159 rfkill_op_pending = true;
160 if (op == RFKILL_GLOBAL_OP_EPO && !rfkill_is_epo_lock_active()) {
161 /* bypass the limiter for EPO */
162 mod_delayed_work(system_wq, &rfkill_op_work, 0);
163 rfkill_last_scheduled = jiffies;
164 } else
165 rfkill_schedule_ratelimited();
166 spin_unlock_irqrestore(&rfkill_op_lock, flags);
167}
168
169static void rfkill_schedule_toggle(enum rfkill_type type)
170{
171 unsigned long flags;
172
173 if (rfkill_is_epo_lock_active())
174 return;
175
176 spin_lock_irqsave(&rfkill_op_lock, flags);
177 if (!rfkill_op_pending) {
178 __set_bit(type, rfkill_sw_pending);
179 __change_bit(type, rfkill_sw_state);
180 rfkill_schedule_ratelimited();
181 }
182 spin_unlock_irqrestore(&rfkill_op_lock, flags);
183}
184
185static void rfkill_schedule_evsw_rfkillall(int state)
186{
187 if (state)
188 rfkill_schedule_global_op(rfkill_master_switch_op);
189 else
190 rfkill_schedule_global_op(RFKILL_GLOBAL_OP_EPO);
191}
192
193static void rfkill_event(struct input_handle *handle, unsigned int type,
194 unsigned int code, int data)
195{
196 if (type == EV_KEY && data == 1) {
197 switch (code) {
198 case KEY_WLAN:
199 rfkill_schedule_toggle(RFKILL_TYPE_WLAN);
200 break;
201 case KEY_BLUETOOTH:
202 rfkill_schedule_toggle(RFKILL_TYPE_BLUETOOTH);
203 break;
204 case KEY_UWB:
205 rfkill_schedule_toggle(RFKILL_TYPE_UWB);
206 break;
207 case KEY_WIMAX:
208 rfkill_schedule_toggle(RFKILL_TYPE_WIMAX);
209 break;
210 case KEY_RFKILL:
211 rfkill_schedule_toggle(RFKILL_TYPE_ALL);
212 break;
213 }
214 } else if (type == EV_SW && code == SW_RFKILL_ALL)
215 rfkill_schedule_evsw_rfkillall(data);
216}
217
218static int rfkill_connect(struct input_handler *handler, struct input_dev *dev,
219 const struct input_device_id *id)
220{
221 struct input_handle *handle;
222 int error;
223
224 handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL);
225 if (!handle)
226 return -ENOMEM;
227
228 handle->dev = dev;
229 handle->handler = handler;
230 handle->name = "rfkill";
231
232 /* causes rfkill_start() to be called */
233 error = input_register_handle(handle);
234 if (error)
235 goto err_free_handle;
236
237 error = input_open_device(handle);
238 if (error)
239 goto err_unregister_handle;
240
241 return 0;
242
243 err_unregister_handle:
244 input_unregister_handle(handle);
245 err_free_handle:
246 kfree(handle);
247 return error;
248}
249
250static void rfkill_start(struct input_handle *handle)
251{
252 /*
253 * Take event_lock to guard against configuration changes, we
254 * should be able to deal with concurrency with rfkill_event()
255 * just fine (which event_lock will also avoid).
256 */
257 spin_lock_irq(&handle->dev->event_lock);
258
259 if (test_bit(EV_SW, handle->dev->evbit) &&
260 test_bit(SW_RFKILL_ALL, handle->dev->swbit))
261 rfkill_schedule_evsw_rfkillall(test_bit(SW_RFKILL_ALL,
262 handle->dev->sw));
263
264 spin_unlock_irq(&handle->dev->event_lock);
265}
266
267static void rfkill_disconnect(struct input_handle *handle)
268{
269 input_close_device(handle);
270 input_unregister_handle(handle);
271 kfree(handle);
272}
273
274static const struct input_device_id rfkill_ids[] = {
275 {
276 .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_KEYBIT,
277 .evbit = { BIT_MASK(EV_KEY) },
278 .keybit = { [BIT_WORD(KEY_WLAN)] = BIT_MASK(KEY_WLAN) },
279 },
280 {
281 .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_KEYBIT,
282 .evbit = { BIT_MASK(EV_KEY) },
283 .keybit = { [BIT_WORD(KEY_BLUETOOTH)] = BIT_MASK(KEY_BLUETOOTH) },
284 },
285 {
286 .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_KEYBIT,
287 .evbit = { BIT_MASK(EV_KEY) },
288 .keybit = { [BIT_WORD(KEY_UWB)] = BIT_MASK(KEY_UWB) },
289 },
290 {
291 .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_KEYBIT,
292 .evbit = { BIT_MASK(EV_KEY) },
293 .keybit = { [BIT_WORD(KEY_WIMAX)] = BIT_MASK(KEY_WIMAX) },
294 },
295 {
296 .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_KEYBIT,
297 .evbit = { BIT_MASK(EV_KEY) },
298 .keybit = { [BIT_WORD(KEY_RFKILL)] = BIT_MASK(KEY_RFKILL) },
299 },
300 {
301 .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_SWBIT,
302 .evbit = { BIT(EV_SW) },
303 .swbit = { [BIT_WORD(SW_RFKILL_ALL)] = BIT_MASK(SW_RFKILL_ALL) },
304 },
305 { }
306};
307
308static struct input_handler rfkill_handler = {
309 .name = "rfkill",
310 .event = rfkill_event,
311 .connect = rfkill_connect,
312 .start = rfkill_start,
313 .disconnect = rfkill_disconnect,
314 .id_table = rfkill_ids,
315};
316
317int __init rfkill_handler_init(void)
318{
319 switch (rfkill_master_switch_mode) {
320 case RFKILL_INPUT_MASTER_UNBLOCKALL:
321 rfkill_master_switch_op = RFKILL_GLOBAL_OP_UNBLOCK;
322 break;
323 case RFKILL_INPUT_MASTER_RESTORE:
324 rfkill_master_switch_op = RFKILL_GLOBAL_OP_RESTORE;
325 break;
326 case RFKILL_INPUT_MASTER_UNLOCK:
327 rfkill_master_switch_op = RFKILL_GLOBAL_OP_UNLOCK;
328 break;
329 default:
330 return -EINVAL;
331 }
332
333 spin_lock_init(&rfkill_op_lock);
334
335 /* Avoid delay at first schedule */
336 rfkill_last_scheduled =
337 jiffies - msecs_to_jiffies(RFKILL_OPS_DELAY) - 1;
338 return input_register_handler(&rfkill_handler);
339}
340
341void __exit rfkill_handler_exit(void)
342{
343 input_unregister_handler(&rfkill_handler);
344 cancel_delayed_work_sync(&rfkill_op_work);
345}
1/*
2 * Input layer to RF Kill interface connector
3 *
4 * Copyright (c) 2007 Dmitry Torokhov
5 * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published
9 * by the Free Software Foundation.
10 *
11 * If you ever run into a situation in which you have a SW_ type rfkill
12 * input device, then you can revive code that was removed in the patch
13 * "rfkill-input: remove unused code".
14 */
15
16#include <linux/input.h>
17#include <linux/slab.h>
18#include <linux/moduleparam.h>
19#include <linux/workqueue.h>
20#include <linux/init.h>
21#include <linux/rfkill.h>
22#include <linux/sched.h>
23
24#include "rfkill.h"
25
26enum rfkill_input_master_mode {
27 RFKILL_INPUT_MASTER_UNLOCK = 0,
28 RFKILL_INPUT_MASTER_RESTORE = 1,
29 RFKILL_INPUT_MASTER_UNBLOCKALL = 2,
30 NUM_RFKILL_INPUT_MASTER_MODES
31};
32
33/* Delay (in ms) between consecutive switch ops */
34#define RFKILL_OPS_DELAY 200
35
36static enum rfkill_input_master_mode rfkill_master_switch_mode =
37 RFKILL_INPUT_MASTER_UNBLOCKALL;
38module_param_named(master_switch_mode, rfkill_master_switch_mode, uint, 0);
39MODULE_PARM_DESC(master_switch_mode,
40 "SW_RFKILL_ALL ON should: 0=do nothing (only unlock); 1=restore; 2=unblock all");
41
42static spinlock_t rfkill_op_lock;
43static bool rfkill_op_pending;
44static unsigned long rfkill_sw_pending[BITS_TO_LONGS(NUM_RFKILL_TYPES)];
45static unsigned long rfkill_sw_state[BITS_TO_LONGS(NUM_RFKILL_TYPES)];
46
47enum rfkill_sched_op {
48 RFKILL_GLOBAL_OP_EPO = 0,
49 RFKILL_GLOBAL_OP_RESTORE,
50 RFKILL_GLOBAL_OP_UNLOCK,
51 RFKILL_GLOBAL_OP_UNBLOCK,
52};
53
54static enum rfkill_sched_op rfkill_master_switch_op;
55static enum rfkill_sched_op rfkill_op;
56
57static void __rfkill_handle_global_op(enum rfkill_sched_op op)
58{
59 unsigned int i;
60
61 switch (op) {
62 case RFKILL_GLOBAL_OP_EPO:
63 rfkill_epo();
64 break;
65 case RFKILL_GLOBAL_OP_RESTORE:
66 rfkill_restore_states();
67 break;
68 case RFKILL_GLOBAL_OP_UNLOCK:
69 rfkill_remove_epo_lock();
70 break;
71 case RFKILL_GLOBAL_OP_UNBLOCK:
72 rfkill_remove_epo_lock();
73 for (i = 0; i < NUM_RFKILL_TYPES; i++)
74 rfkill_switch_all(i, false);
75 break;
76 default:
77 /* memory corruption or bug, fail safely */
78 rfkill_epo();
79 WARN(1, "Unknown requested operation %d! "
80 "rfkill Emergency Power Off activated\n",
81 op);
82 }
83}
84
85static void __rfkill_handle_normal_op(const enum rfkill_type type,
86 const bool complement)
87{
88 bool blocked;
89
90 blocked = rfkill_get_global_sw_state(type);
91 if (complement)
92 blocked = !blocked;
93
94 rfkill_switch_all(type, blocked);
95}
96
97static void rfkill_op_handler(struct work_struct *work)
98{
99 unsigned int i;
100 bool c;
101
102 spin_lock_irq(&rfkill_op_lock);
103 do {
104 if (rfkill_op_pending) {
105 enum rfkill_sched_op op = rfkill_op;
106 rfkill_op_pending = false;
107 memset(rfkill_sw_pending, 0,
108 sizeof(rfkill_sw_pending));
109 spin_unlock_irq(&rfkill_op_lock);
110
111 __rfkill_handle_global_op(op);
112
113 spin_lock_irq(&rfkill_op_lock);
114
115 /*
116 * handle global ops first -- during unlocked period
117 * we might have gotten a new global op.
118 */
119 if (rfkill_op_pending)
120 continue;
121 }
122
123 if (rfkill_is_epo_lock_active())
124 continue;
125
126 for (i = 0; i < NUM_RFKILL_TYPES; i++) {
127 if (__test_and_clear_bit(i, rfkill_sw_pending)) {
128 c = __test_and_clear_bit(i, rfkill_sw_state);
129 spin_unlock_irq(&rfkill_op_lock);
130
131 __rfkill_handle_normal_op(i, c);
132
133 spin_lock_irq(&rfkill_op_lock);
134 }
135 }
136 } while (rfkill_op_pending);
137 spin_unlock_irq(&rfkill_op_lock);
138}
139
140static DECLARE_DELAYED_WORK(rfkill_op_work, rfkill_op_handler);
141static unsigned long rfkill_last_scheduled;
142
143static unsigned long rfkill_ratelimit(const unsigned long last)
144{
145 const unsigned long delay = msecs_to_jiffies(RFKILL_OPS_DELAY);
146 return time_after(jiffies, last + delay) ? 0 : delay;
147}
148
149static void rfkill_schedule_ratelimited(void)
150{
151 if (schedule_delayed_work(&rfkill_op_work,
152 rfkill_ratelimit(rfkill_last_scheduled)))
153 rfkill_last_scheduled = jiffies;
154}
155
156static void rfkill_schedule_global_op(enum rfkill_sched_op op)
157{
158 unsigned long flags;
159
160 spin_lock_irqsave(&rfkill_op_lock, flags);
161 rfkill_op = op;
162 rfkill_op_pending = true;
163 if (op == RFKILL_GLOBAL_OP_EPO && !rfkill_is_epo_lock_active()) {
164 /* bypass the limiter for EPO */
165 mod_delayed_work(system_wq, &rfkill_op_work, 0);
166 rfkill_last_scheduled = jiffies;
167 } else
168 rfkill_schedule_ratelimited();
169 spin_unlock_irqrestore(&rfkill_op_lock, flags);
170}
171
172static void rfkill_schedule_toggle(enum rfkill_type type)
173{
174 unsigned long flags;
175
176 if (rfkill_is_epo_lock_active())
177 return;
178
179 spin_lock_irqsave(&rfkill_op_lock, flags);
180 if (!rfkill_op_pending) {
181 __set_bit(type, rfkill_sw_pending);
182 __change_bit(type, rfkill_sw_state);
183 rfkill_schedule_ratelimited();
184 }
185 spin_unlock_irqrestore(&rfkill_op_lock, flags);
186}
187
188static void rfkill_schedule_evsw_rfkillall(int state)
189{
190 if (state)
191 rfkill_schedule_global_op(rfkill_master_switch_op);
192 else
193 rfkill_schedule_global_op(RFKILL_GLOBAL_OP_EPO);
194}
195
196static void rfkill_event(struct input_handle *handle, unsigned int type,
197 unsigned int code, int data)
198{
199 if (type == EV_KEY && data == 1) {
200 switch (code) {
201 case KEY_WLAN:
202 rfkill_schedule_toggle(RFKILL_TYPE_WLAN);
203 break;
204 case KEY_BLUETOOTH:
205 rfkill_schedule_toggle(RFKILL_TYPE_BLUETOOTH);
206 break;
207 case KEY_UWB:
208 rfkill_schedule_toggle(RFKILL_TYPE_UWB);
209 break;
210 case KEY_WIMAX:
211 rfkill_schedule_toggle(RFKILL_TYPE_WIMAX);
212 break;
213 case KEY_RFKILL:
214 rfkill_schedule_toggle(RFKILL_TYPE_ALL);
215 break;
216 }
217 } else if (type == EV_SW && code == SW_RFKILL_ALL)
218 rfkill_schedule_evsw_rfkillall(data);
219}
220
221static int rfkill_connect(struct input_handler *handler, struct input_dev *dev,
222 const struct input_device_id *id)
223{
224 struct input_handle *handle;
225 int error;
226
227 handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL);
228 if (!handle)
229 return -ENOMEM;
230
231 handle->dev = dev;
232 handle->handler = handler;
233 handle->name = "rfkill";
234
235 /* causes rfkill_start() to be called */
236 error = input_register_handle(handle);
237 if (error)
238 goto err_free_handle;
239
240 error = input_open_device(handle);
241 if (error)
242 goto err_unregister_handle;
243
244 return 0;
245
246 err_unregister_handle:
247 input_unregister_handle(handle);
248 err_free_handle:
249 kfree(handle);
250 return error;
251}
252
253static void rfkill_start(struct input_handle *handle)
254{
255 /*
256 * Take event_lock to guard against configuration changes, we
257 * should be able to deal with concurrency with rfkill_event()
258 * just fine (which event_lock will also avoid).
259 */
260 spin_lock_irq(&handle->dev->event_lock);
261
262 if (test_bit(EV_SW, handle->dev->evbit) &&
263 test_bit(SW_RFKILL_ALL, handle->dev->swbit))
264 rfkill_schedule_evsw_rfkillall(test_bit(SW_RFKILL_ALL,
265 handle->dev->sw));
266
267 spin_unlock_irq(&handle->dev->event_lock);
268}
269
270static void rfkill_disconnect(struct input_handle *handle)
271{
272 input_close_device(handle);
273 input_unregister_handle(handle);
274 kfree(handle);
275}
276
277static const struct input_device_id rfkill_ids[] = {
278 {
279 .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_KEYBIT,
280 .evbit = { BIT_MASK(EV_KEY) },
281 .keybit = { [BIT_WORD(KEY_WLAN)] = BIT_MASK(KEY_WLAN) },
282 },
283 {
284 .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_KEYBIT,
285 .evbit = { BIT_MASK(EV_KEY) },
286 .keybit = { [BIT_WORD(KEY_BLUETOOTH)] = BIT_MASK(KEY_BLUETOOTH) },
287 },
288 {
289 .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_KEYBIT,
290 .evbit = { BIT_MASK(EV_KEY) },
291 .keybit = { [BIT_WORD(KEY_UWB)] = BIT_MASK(KEY_UWB) },
292 },
293 {
294 .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_KEYBIT,
295 .evbit = { BIT_MASK(EV_KEY) },
296 .keybit = { [BIT_WORD(KEY_WIMAX)] = BIT_MASK(KEY_WIMAX) },
297 },
298 {
299 .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_KEYBIT,
300 .evbit = { BIT_MASK(EV_KEY) },
301 .keybit = { [BIT_WORD(KEY_RFKILL)] = BIT_MASK(KEY_RFKILL) },
302 },
303 {
304 .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_SWBIT,
305 .evbit = { BIT(EV_SW) },
306 .swbit = { [BIT_WORD(SW_RFKILL_ALL)] = BIT_MASK(SW_RFKILL_ALL) },
307 },
308 { }
309};
310
311static struct input_handler rfkill_handler = {
312 .name = "rfkill",
313 .event = rfkill_event,
314 .connect = rfkill_connect,
315 .start = rfkill_start,
316 .disconnect = rfkill_disconnect,
317 .id_table = rfkill_ids,
318};
319
320int __init rfkill_handler_init(void)
321{
322 switch (rfkill_master_switch_mode) {
323 case RFKILL_INPUT_MASTER_UNBLOCKALL:
324 rfkill_master_switch_op = RFKILL_GLOBAL_OP_UNBLOCK;
325 break;
326 case RFKILL_INPUT_MASTER_RESTORE:
327 rfkill_master_switch_op = RFKILL_GLOBAL_OP_RESTORE;
328 break;
329 case RFKILL_INPUT_MASTER_UNLOCK:
330 rfkill_master_switch_op = RFKILL_GLOBAL_OP_UNLOCK;
331 break;
332 default:
333 return -EINVAL;
334 }
335
336 spin_lock_init(&rfkill_op_lock);
337
338 /* Avoid delay at first schedule */
339 rfkill_last_scheduled =
340 jiffies - msecs_to_jiffies(RFKILL_OPS_DELAY) - 1;
341 return input_register_handler(&rfkill_handler);
342}
343
344void __exit rfkill_handler_exit(void)
345{
346 input_unregister_handler(&rfkill_handler);
347 cancel_delayed_work_sync(&rfkill_op_work);
348}