16 #include <linux/input.h>
17 #include <linux/slab.h>
21 #include <linux/rfkill.h>
22 #include <linux/sched.h>
34 #define RFKILL_OPS_DELAY 200
40 "SW_RFKILL_ALL ON should: 0=do nothing (only unlock); 1=restore; 2=unblock all");
43 static bool rfkill_op_pending;
79 WARN(1,
"Unknown requested operation %d! "
80 "rfkill Emergency Power Off activated\n",
86 const bool complement)
102 spin_lock_irq(&rfkill_op_lock);
104 if (rfkill_op_pending) {
106 rfkill_op_pending =
false;
107 memset(rfkill_sw_pending, 0,
108 sizeof(rfkill_sw_pending));
109 spin_unlock_irq(&rfkill_op_lock);
111 __rfkill_handle_global_op(op);
113 spin_lock_irq(&rfkill_op_lock);
119 if (rfkill_op_pending)
129 spin_unlock_irq(&rfkill_op_lock);
131 __rfkill_handle_normal_op(i, c);
133 spin_lock_irq(&rfkill_op_lock);
136 }
while (rfkill_op_pending);
137 spin_unlock_irq(&rfkill_op_lock);
141 static unsigned long rfkill_last_scheduled;
143 static unsigned long rfkill_ratelimit(
const unsigned long last)
149 static void rfkill_schedule_ratelimited(
void)
154 rfkill_ratelimit(rfkill_last_scheduled));
155 rfkill_last_scheduled =
jiffies;
164 rfkill_op_pending =
true;
168 rfkill_last_scheduled =
jiffies;
170 rfkill_schedule_ratelimited();
171 spin_unlock_irqrestore(&rfkill_op_lock, flags);
174 static void rfkill_schedule_toggle(
enum rfkill_type type)
182 if (!rfkill_op_pending) {
185 rfkill_schedule_ratelimited();
187 spin_unlock_irqrestore(&rfkill_op_lock, flags);
190 static void rfkill_schedule_evsw_rfkillall(
int state)
193 rfkill_schedule_global_op(rfkill_master_switch_op);
201 if (type ==
EV_KEY && data == 1) {
220 rfkill_schedule_evsw_rfkillall(data);
223 static int rfkill_connect(
struct input_handler *handler,
struct input_dev *
dev,
226 struct input_handle *
handle;
229 handle = kzalloc(
sizeof(
struct input_handle),
GFP_KERNEL);
234 handle->handler = handler;
235 handle->name =
"rfkill";
238 error = input_register_handle(handle);
240 goto err_free_handle;
242 error = input_open_device(handle);
244 goto err_unregister_handle;
248 err_unregister_handle:
249 input_unregister_handle(handle);
255 static void rfkill_start(
struct input_handle *handle)
262 spin_lock_irq(&handle->dev->event_lock);
269 spin_unlock_irq(&handle->dev->event_lock);
272 static void rfkill_disconnect(
struct input_handle *handle)
274 input_close_device(handle);
275 input_unregister_handle(handle);
313 static struct input_handler rfkill_handler = {
316 .connect = rfkill_connect,
317 .start = rfkill_start,
318 .disconnect = rfkill_disconnect,
319 .id_table = rfkill_ids,
324 switch (rfkill_master_switch_mode) {
341 rfkill_last_scheduled =
343 return input_register_handler(&rfkill_handler);
348 input_unregister_handler(&rfkill_handler);