Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * The input core |
| 3 | * |
| 4 | * Copyright (c) 1999-2002 Vojtech Pavlik |
| 5 | */ |
| 6 | |
| 7 | /* |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public License version 2 as published by |
| 10 | * the Free Software Foundation. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/init.h> |
Dmitry Torokhov | ffd0db9 | 2009-09-16 01:06:43 -0700 | [diff] [blame] | 14 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/input.h> |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/random.h> |
| 18 | #include <linux/major.h> |
| 19 | #include <linux/proc_fs.h> |
Alexey Dobriyan | a99bbaf | 2009-10-04 16:11:37 +0400 | [diff] [blame] | 20 | #include <linux/sched.h> |
Dmitry Torokhov | 969b21c | 2006-04-02 00:09:34 -0500 | [diff] [blame] | 21 | #include <linux/seq_file.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/poll.h> |
| 23 | #include <linux/device.h> |
Jes Sorensen | e676c23 | 2006-02-19 00:21:46 -0500 | [diff] [blame] | 24 | #include <linux/mutex.h> |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 25 | #include <linux/rcupdate.h> |
Jonathan Corbet | 2edbf85 | 2008-05-15 10:37:16 -0600 | [diff] [blame] | 26 | #include <linux/smp_lock.h> |
Dmitry Torokhov | 15e184a | 2010-01-11 00:05:43 -0800 | [diff] [blame] | 27 | #include "input-compat.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
| 29 | MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>"); |
| 30 | MODULE_DESCRIPTION("Input core"); |
| 31 | MODULE_LICENSE("GPL"); |
| 32 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #define INPUT_DEVICES 256 |
| 34 | |
Henrik Rydberg | 61994a6 | 2009-04-28 07:45:31 -0700 | [diff] [blame] | 35 | /* |
| 36 | * EV_ABS events which should not be cached are listed here. |
| 37 | */ |
| 38 | static unsigned int input_abs_bypass_init_data[] __initdata = { |
Henrik Rydberg | 5e5ee68 | 2009-04-28 07:47:33 -0700 | [diff] [blame] | 39 | ABS_MT_TOUCH_MAJOR, |
| 40 | ABS_MT_TOUCH_MINOR, |
| 41 | ABS_MT_WIDTH_MAJOR, |
| 42 | ABS_MT_WIDTH_MINOR, |
| 43 | ABS_MT_ORIENTATION, |
| 44 | ABS_MT_POSITION_X, |
| 45 | ABS_MT_POSITION_Y, |
| 46 | ABS_MT_TOOL_TYPE, |
| 47 | ABS_MT_BLOB_ID, |
Henrik Rydberg | df391e0 | 2009-05-23 09:51:20 -0700 | [diff] [blame] | 48 | ABS_MT_TRACKING_ID, |
Henrik Rydberg | cb6ecf6 | 2010-01-28 22:28:27 -0800 | [diff] [blame] | 49 | ABS_MT_PRESSURE, |
Henrik Rydberg | 61994a6 | 2009-04-28 07:45:31 -0700 | [diff] [blame] | 50 | 0 |
| 51 | }; |
| 52 | static unsigned long input_abs_bypass[BITS_TO_LONGS(ABS_CNT)]; |
| 53 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | static LIST_HEAD(input_dev_list); |
| 55 | static LIST_HEAD(input_handler_list); |
| 56 | |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 57 | /* |
| 58 | * input_mutex protects access to both input_dev_list and input_handler_list. |
| 59 | * This also causes input_[un]register_device and input_[un]register_handler |
| 60 | * be mutually exclusive which simplifies locking in drivers implementing |
| 61 | * input handlers. |
| 62 | */ |
| 63 | static DEFINE_MUTEX(input_mutex); |
| 64 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | static struct input_handler *input_table[8]; |
| 66 | |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 67 | static inline int is_event_supported(unsigned int code, |
| 68 | unsigned long *bm, unsigned int max) |
| 69 | { |
| 70 | return code <= max && test_bit(code, bm); |
| 71 | } |
| 72 | |
| 73 | static int input_defuzz_abs_event(int value, int old_val, int fuzz) |
| 74 | { |
| 75 | if (fuzz) { |
| 76 | if (value > old_val - fuzz / 2 && value < old_val + fuzz / 2) |
| 77 | return old_val; |
| 78 | |
| 79 | if (value > old_val - fuzz && value < old_val + fuzz) |
| 80 | return (old_val * 3 + value) / 4; |
| 81 | |
| 82 | if (value > old_val - fuzz * 2 && value < old_val + fuzz * 2) |
| 83 | return (old_val + value) / 2; |
| 84 | } |
| 85 | |
| 86 | return value; |
| 87 | } |
| 88 | |
| 89 | /* |
Dmitry Torokhov | ef7995f | 2010-01-29 23:59:12 -0800 | [diff] [blame] | 90 | * Pass event first through all filters and then, if event has not been |
| 91 | * filtered out, through all open handles. This function is called with |
Dmitry Torokhov | 82ba56c | 2007-10-13 15:46:55 -0400 | [diff] [blame] | 92 | * dev->event_lock held and interrupts disabled. |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 93 | */ |
| 94 | static void input_pass_event(struct input_dev *dev, |
| 95 | unsigned int type, unsigned int code, int value) |
| 96 | { |
Dmitry Torokhov | ef7995f | 2010-01-29 23:59:12 -0800 | [diff] [blame] | 97 | struct input_handler *handler; |
Dmitry Torokhov | 82ba56c | 2007-10-13 15:46:55 -0400 | [diff] [blame] | 98 | struct input_handle *handle; |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 99 | |
Dmitry Torokhov | 82ba56c | 2007-10-13 15:46:55 -0400 | [diff] [blame] | 100 | rcu_read_lock(); |
| 101 | |
| 102 | handle = rcu_dereference(dev->grab); |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 103 | if (handle) |
| 104 | handle->handler->event(handle, type, code, value); |
Dmitry Torokhov | ef7995f | 2010-01-29 23:59:12 -0800 | [diff] [blame] | 105 | else { |
| 106 | bool filtered = false; |
| 107 | |
| 108 | list_for_each_entry_rcu(handle, &dev->h_list, d_node) { |
| 109 | if (!handle->open) |
| 110 | continue; |
| 111 | |
| 112 | handler = handle->handler; |
| 113 | if (!handler->filter) { |
| 114 | if (filtered) |
| 115 | break; |
| 116 | |
| 117 | handler->event(handle, type, code, value); |
| 118 | |
| 119 | } else if (handler->filter(handle, type, code, value)) |
| 120 | filtered = true; |
| 121 | } |
| 122 | } |
| 123 | |
Dmitry Torokhov | 82ba56c | 2007-10-13 15:46:55 -0400 | [diff] [blame] | 124 | rcu_read_unlock(); |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | /* |
| 128 | * Generate software autorepeat event. Note that we take |
| 129 | * dev->event_lock here to avoid racing with input_event |
| 130 | * which may cause keys get "stuck". |
| 131 | */ |
| 132 | static void input_repeat_key(unsigned long data) |
| 133 | { |
| 134 | struct input_dev *dev = (void *) data; |
| 135 | unsigned long flags; |
| 136 | |
| 137 | spin_lock_irqsave(&dev->event_lock, flags); |
| 138 | |
| 139 | if (test_bit(dev->repeat_key, dev->key) && |
| 140 | is_event_supported(dev->repeat_key, dev->keybit, KEY_MAX)) { |
| 141 | |
| 142 | input_pass_event(dev, EV_KEY, dev->repeat_key, 2); |
| 143 | |
| 144 | if (dev->sync) { |
| 145 | /* |
| 146 | * Only send SYN_REPORT if we are not in a middle |
| 147 | * of driver parsing a new hardware packet. |
| 148 | * Otherwise assume that the driver will send |
| 149 | * SYN_REPORT once it's done. |
| 150 | */ |
| 151 | input_pass_event(dev, EV_SYN, SYN_REPORT, 1); |
| 152 | } |
| 153 | |
| 154 | if (dev->rep[REP_PERIOD]) |
| 155 | mod_timer(&dev->timer, jiffies + |
| 156 | msecs_to_jiffies(dev->rep[REP_PERIOD])); |
| 157 | } |
| 158 | |
| 159 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 160 | } |
| 161 | |
| 162 | static void input_start_autorepeat(struct input_dev *dev, int code) |
| 163 | { |
| 164 | if (test_bit(EV_REP, dev->evbit) && |
| 165 | dev->rep[REP_PERIOD] && dev->rep[REP_DELAY] && |
| 166 | dev->timer.data) { |
| 167 | dev->repeat_key = code; |
| 168 | mod_timer(&dev->timer, |
| 169 | jiffies + msecs_to_jiffies(dev->rep[REP_DELAY])); |
| 170 | } |
| 171 | } |
| 172 | |
Johannes Berg | e7b5c1e | 2009-01-29 23:17:52 -0800 | [diff] [blame] | 173 | static void input_stop_autorepeat(struct input_dev *dev) |
| 174 | { |
| 175 | del_timer(&dev->timer); |
| 176 | } |
| 177 | |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 178 | #define INPUT_IGNORE_EVENT 0 |
| 179 | #define INPUT_PASS_TO_HANDLERS 1 |
| 180 | #define INPUT_PASS_TO_DEVICE 2 |
| 181 | #define INPUT_PASS_TO_ALL (INPUT_PASS_TO_HANDLERS | INPUT_PASS_TO_DEVICE) |
| 182 | |
| 183 | static void input_handle_event(struct input_dev *dev, |
| 184 | unsigned int type, unsigned int code, int value) |
| 185 | { |
| 186 | int disposition = INPUT_IGNORE_EVENT; |
| 187 | |
| 188 | switch (type) { |
| 189 | |
| 190 | case EV_SYN: |
| 191 | switch (code) { |
| 192 | case SYN_CONFIG: |
| 193 | disposition = INPUT_PASS_TO_ALL; |
| 194 | break; |
| 195 | |
| 196 | case SYN_REPORT: |
| 197 | if (!dev->sync) { |
| 198 | dev->sync = 1; |
| 199 | disposition = INPUT_PASS_TO_HANDLERS; |
| 200 | } |
| 201 | break; |
Henrik Rydberg | 5e5ee68 | 2009-04-28 07:47:33 -0700 | [diff] [blame] | 202 | case SYN_MT_REPORT: |
| 203 | dev->sync = 0; |
| 204 | disposition = INPUT_PASS_TO_HANDLERS; |
| 205 | break; |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 206 | } |
| 207 | break; |
| 208 | |
| 209 | case EV_KEY: |
| 210 | if (is_event_supported(code, dev->keybit, KEY_MAX) && |
| 211 | !!test_bit(code, dev->key) != value) { |
| 212 | |
| 213 | if (value != 2) { |
| 214 | __change_bit(code, dev->key); |
| 215 | if (value) |
| 216 | input_start_autorepeat(dev, code); |
Johannes Berg | e7b5c1e | 2009-01-29 23:17:52 -0800 | [diff] [blame] | 217 | else |
| 218 | input_stop_autorepeat(dev); |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | disposition = INPUT_PASS_TO_HANDLERS; |
| 222 | } |
| 223 | break; |
| 224 | |
| 225 | case EV_SW: |
| 226 | if (is_event_supported(code, dev->swbit, SW_MAX) && |
| 227 | !!test_bit(code, dev->sw) != value) { |
| 228 | |
| 229 | __change_bit(code, dev->sw); |
| 230 | disposition = INPUT_PASS_TO_HANDLERS; |
| 231 | } |
| 232 | break; |
| 233 | |
| 234 | case EV_ABS: |
| 235 | if (is_event_supported(code, dev->absbit, ABS_MAX)) { |
| 236 | |
Henrik Rydberg | 61994a6 | 2009-04-28 07:45:31 -0700 | [diff] [blame] | 237 | if (test_bit(code, input_abs_bypass)) { |
| 238 | disposition = INPUT_PASS_TO_HANDLERS; |
| 239 | break; |
| 240 | } |
| 241 | |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 242 | value = input_defuzz_abs_event(value, |
| 243 | dev->abs[code], dev->absfuzz[code]); |
| 244 | |
| 245 | if (dev->abs[code] != value) { |
| 246 | dev->abs[code] = value; |
| 247 | disposition = INPUT_PASS_TO_HANDLERS; |
| 248 | } |
| 249 | } |
| 250 | break; |
| 251 | |
| 252 | case EV_REL: |
| 253 | if (is_event_supported(code, dev->relbit, REL_MAX) && value) |
| 254 | disposition = INPUT_PASS_TO_HANDLERS; |
| 255 | |
| 256 | break; |
| 257 | |
| 258 | case EV_MSC: |
| 259 | if (is_event_supported(code, dev->mscbit, MSC_MAX)) |
| 260 | disposition = INPUT_PASS_TO_ALL; |
| 261 | |
| 262 | break; |
| 263 | |
| 264 | case EV_LED: |
| 265 | if (is_event_supported(code, dev->ledbit, LED_MAX) && |
| 266 | !!test_bit(code, dev->led) != value) { |
| 267 | |
| 268 | __change_bit(code, dev->led); |
| 269 | disposition = INPUT_PASS_TO_ALL; |
| 270 | } |
| 271 | break; |
| 272 | |
| 273 | case EV_SND: |
| 274 | if (is_event_supported(code, dev->sndbit, SND_MAX)) { |
| 275 | |
| 276 | if (!!test_bit(code, dev->snd) != !!value) |
| 277 | __change_bit(code, dev->snd); |
| 278 | disposition = INPUT_PASS_TO_ALL; |
| 279 | } |
| 280 | break; |
| 281 | |
| 282 | case EV_REP: |
| 283 | if (code <= REP_MAX && value >= 0 && dev->rep[code] != value) { |
| 284 | dev->rep[code] = value; |
| 285 | disposition = INPUT_PASS_TO_ALL; |
| 286 | } |
| 287 | break; |
| 288 | |
| 289 | case EV_FF: |
| 290 | if (value >= 0) |
| 291 | disposition = INPUT_PASS_TO_ALL; |
| 292 | break; |
Richard Purdie | ed2fa4d | 2008-01-03 10:46:21 -0500 | [diff] [blame] | 293 | |
| 294 | case EV_PWR: |
| 295 | disposition = INPUT_PASS_TO_ALL; |
| 296 | break; |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 297 | } |
| 298 | |
Dmitry Torokhov | c981228 | 2008-06-02 01:02:40 -0400 | [diff] [blame] | 299 | if (disposition != INPUT_IGNORE_EVENT && type != EV_SYN) |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 300 | dev->sync = 0; |
| 301 | |
| 302 | if ((disposition & INPUT_PASS_TO_DEVICE) && dev->event) |
| 303 | dev->event(dev, type, code, value); |
| 304 | |
| 305 | if (disposition & INPUT_PASS_TO_HANDLERS) |
| 306 | input_pass_event(dev, type, code, value); |
| 307 | } |
| 308 | |
Dmitry Torokhov | 0e739d2 | 2006-07-06 00:22:43 -0400 | [diff] [blame] | 309 | /** |
| 310 | * input_event() - report new input event |
Dmitry Torokhov | 1447190 | 2006-11-02 23:26:55 -0500 | [diff] [blame] | 311 | * @dev: device that generated the event |
Dmitry Torokhov | 0e739d2 | 2006-07-06 00:22:43 -0400 | [diff] [blame] | 312 | * @type: type of the event |
| 313 | * @code: event code |
| 314 | * @value: value of the event |
| 315 | * |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 316 | * This function should be used by drivers implementing various input |
Dmitry Torokhov | df2d463 | 2009-12-11 21:57:31 -0800 | [diff] [blame] | 317 | * devices to report input events. See also input_inject_event(). |
| 318 | * |
| 319 | * NOTE: input_event() may be safely used right after input device was |
| 320 | * allocated with input_allocate_device(), even before it is registered |
| 321 | * with input_register_device(), but the event will not reach any of the |
| 322 | * input handlers. Such early invocation of input_event() may be used |
| 323 | * to 'seed' initial state of a switch or initial position of absolute |
| 324 | * axis, etc. |
Dmitry Torokhov | 0e739d2 | 2006-07-06 00:22:43 -0400 | [diff] [blame] | 325 | */ |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 326 | void input_event(struct input_dev *dev, |
| 327 | unsigned int type, unsigned int code, int value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | { |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 329 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 331 | if (is_event_supported(type, dev->evbit, EV_MAX)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 333 | spin_lock_irqsave(&dev->event_lock, flags); |
| 334 | add_input_randomness(type, code, value); |
| 335 | input_handle_event(dev, type, code, value); |
| 336 | spin_unlock_irqrestore(&dev->event_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | } |
Dmitry Torokhov | ca56fe0 | 2006-06-26 01:49:21 -0400 | [diff] [blame] | 339 | EXPORT_SYMBOL(input_event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
Dmitry Torokhov | 0e739d2 | 2006-07-06 00:22:43 -0400 | [diff] [blame] | 341 | /** |
| 342 | * input_inject_event() - send input event from input handler |
| 343 | * @handle: input handle to send event through |
| 344 | * @type: type of the event |
| 345 | * @code: event code |
| 346 | * @value: value of the event |
| 347 | * |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 348 | * Similar to input_event() but will ignore event if device is |
| 349 | * "grabbed" and handle injecting event is not the one that owns |
| 350 | * the device. |
Dmitry Torokhov | 0e739d2 | 2006-07-06 00:22:43 -0400 | [diff] [blame] | 351 | */ |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 352 | void input_inject_event(struct input_handle *handle, |
| 353 | unsigned int type, unsigned int code, int value) |
Dmitry Torokhov | 0e739d2 | 2006-07-06 00:22:43 -0400 | [diff] [blame] | 354 | { |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 355 | struct input_dev *dev = handle->dev; |
| 356 | struct input_handle *grab; |
| 357 | unsigned long flags; |
| 358 | |
| 359 | if (is_event_supported(type, dev->evbit, EV_MAX)) { |
| 360 | spin_lock_irqsave(&dev->event_lock, flags); |
| 361 | |
Dmitry Torokhov | 82ba56c | 2007-10-13 15:46:55 -0400 | [diff] [blame] | 362 | rcu_read_lock(); |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 363 | grab = rcu_dereference(dev->grab); |
| 364 | if (!grab || grab == handle) |
| 365 | input_handle_event(dev, type, code, value); |
Dmitry Torokhov | 82ba56c | 2007-10-13 15:46:55 -0400 | [diff] [blame] | 366 | rcu_read_unlock(); |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 367 | |
| 368 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 369 | } |
Dmitry Torokhov | 0e739d2 | 2006-07-06 00:22:43 -0400 | [diff] [blame] | 370 | } |
| 371 | EXPORT_SYMBOL(input_inject_event); |
| 372 | |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 373 | /** |
| 374 | * input_grab_device - grabs device for exclusive use |
| 375 | * @handle: input handle that wants to own the device |
| 376 | * |
| 377 | * When a device is grabbed by an input handle all events generated by |
| 378 | * the device are delivered only to this handle. Also events injected |
| 379 | * by other input handles are ignored while device is grabbed. |
| 380 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | int input_grab_device(struct input_handle *handle) |
| 382 | { |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 383 | struct input_dev *dev = handle->dev; |
| 384 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 386 | retval = mutex_lock_interruptible(&dev->mutex); |
| 387 | if (retval) |
| 388 | return retval; |
| 389 | |
| 390 | if (dev->grab) { |
| 391 | retval = -EBUSY; |
| 392 | goto out; |
| 393 | } |
| 394 | |
| 395 | rcu_assign_pointer(dev->grab, handle); |
Dmitry Torokhov | 82ba56c | 2007-10-13 15:46:55 -0400 | [diff] [blame] | 396 | synchronize_rcu(); |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 397 | |
| 398 | out: |
| 399 | mutex_unlock(&dev->mutex); |
| 400 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | } |
Dmitry Torokhov | ca56fe0 | 2006-06-26 01:49:21 -0400 | [diff] [blame] | 402 | EXPORT_SYMBOL(input_grab_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 404 | static void __input_release_device(struct input_handle *handle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | { |
Andrew Morton | a2b2ed2 | 2006-07-15 01:17:38 -0400 | [diff] [blame] | 406 | struct input_dev *dev = handle->dev; |
Dmitry Torokhov | c7e8dc6 | 2006-07-06 00:21:03 -0400 | [diff] [blame] | 407 | |
Andrew Morton | a2b2ed2 | 2006-07-15 01:17:38 -0400 | [diff] [blame] | 408 | if (dev->grab == handle) { |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 409 | rcu_assign_pointer(dev->grab, NULL); |
| 410 | /* Make sure input_pass_event() notices that grab is gone */ |
Dmitry Torokhov | 82ba56c | 2007-10-13 15:46:55 -0400 | [diff] [blame] | 411 | synchronize_rcu(); |
Andrew Morton | a2b2ed2 | 2006-07-15 01:17:38 -0400 | [diff] [blame] | 412 | |
| 413 | list_for_each_entry(handle, &dev->h_list, d_node) |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 414 | if (handle->open && handle->handler->start) |
Dmitry Torokhov | c7e8dc6 | 2006-07-06 00:21:03 -0400 | [diff] [blame] | 415 | handle->handler->start(handle); |
| 416 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | } |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 418 | |
| 419 | /** |
| 420 | * input_release_device - release previously grabbed device |
| 421 | * @handle: input handle that owns the device |
| 422 | * |
| 423 | * Releases previously grabbed device so that other input handles can |
| 424 | * start receiving input events. Upon release all handlers attached |
| 425 | * to the device have their start() method called so they have a change |
| 426 | * to synchronize device state with the rest of the system. |
| 427 | */ |
| 428 | void input_release_device(struct input_handle *handle) |
| 429 | { |
| 430 | struct input_dev *dev = handle->dev; |
| 431 | |
| 432 | mutex_lock(&dev->mutex); |
| 433 | __input_release_device(handle); |
| 434 | mutex_unlock(&dev->mutex); |
| 435 | } |
Dmitry Torokhov | ca56fe0 | 2006-06-26 01:49:21 -0400 | [diff] [blame] | 436 | EXPORT_SYMBOL(input_release_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 438 | /** |
| 439 | * input_open_device - open input device |
| 440 | * @handle: handle through which device is being accessed |
| 441 | * |
| 442 | * This function should be called by input handlers when they |
| 443 | * want to start receive events from given input device. |
| 444 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | int input_open_device(struct input_handle *handle) |
| 446 | { |
Dmitry Torokhov | 0fbf87c | 2005-05-29 02:29:25 -0500 | [diff] [blame] | 447 | struct input_dev *dev = handle->dev; |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 448 | int retval; |
Dmitry Torokhov | 0fbf87c | 2005-05-29 02:29:25 -0500 | [diff] [blame] | 449 | |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 450 | retval = mutex_lock_interruptible(&dev->mutex); |
| 451 | if (retval) |
| 452 | return retval; |
| 453 | |
| 454 | if (dev->going_away) { |
| 455 | retval = -ENODEV; |
| 456 | goto out; |
| 457 | } |
Dmitry Torokhov | 0fbf87c | 2005-05-29 02:29:25 -0500 | [diff] [blame] | 458 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | handle->open++; |
Dmitry Torokhov | 0fbf87c | 2005-05-29 02:29:25 -0500 | [diff] [blame] | 460 | |
| 461 | if (!dev->users++ && dev->open) |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 462 | retval = dev->open(dev); |
Dmitry Torokhov | 0fbf87c | 2005-05-29 02:29:25 -0500 | [diff] [blame] | 463 | |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 464 | if (retval) { |
| 465 | dev->users--; |
| 466 | if (!--handle->open) { |
| 467 | /* |
| 468 | * Make sure we are not delivering any more events |
| 469 | * through this handle |
| 470 | */ |
Dmitry Torokhov | 82ba56c | 2007-10-13 15:46:55 -0400 | [diff] [blame] | 471 | synchronize_rcu(); |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 472 | } |
| 473 | } |
Dmitry Torokhov | 0fbf87c | 2005-05-29 02:29:25 -0500 | [diff] [blame] | 474 | |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 475 | out: |
Jes Sorensen | e676c23 | 2006-02-19 00:21:46 -0500 | [diff] [blame] | 476 | mutex_unlock(&dev->mutex); |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 477 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | } |
Dmitry Torokhov | ca56fe0 | 2006-06-26 01:49:21 -0400 | [diff] [blame] | 479 | EXPORT_SYMBOL(input_open_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 481 | int input_flush_device(struct input_handle *handle, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | { |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 483 | struct input_dev *dev = handle->dev; |
| 484 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 486 | retval = mutex_lock_interruptible(&dev->mutex); |
| 487 | if (retval) |
| 488 | return retval; |
| 489 | |
| 490 | if (dev->flush) |
| 491 | retval = dev->flush(dev, file); |
| 492 | |
| 493 | mutex_unlock(&dev->mutex); |
| 494 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | } |
Dmitry Torokhov | ca56fe0 | 2006-06-26 01:49:21 -0400 | [diff] [blame] | 496 | EXPORT_SYMBOL(input_flush_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 498 | /** |
| 499 | * input_close_device - close input device |
| 500 | * @handle: handle through which device is being accessed |
| 501 | * |
| 502 | * This function should be called by input handlers when they |
| 503 | * want to stop receive events from given input device. |
| 504 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | void input_close_device(struct input_handle *handle) |
| 506 | { |
Dmitry Torokhov | 0fbf87c | 2005-05-29 02:29:25 -0500 | [diff] [blame] | 507 | struct input_dev *dev = handle->dev; |
| 508 | |
Jes Sorensen | e676c23 | 2006-02-19 00:21:46 -0500 | [diff] [blame] | 509 | mutex_lock(&dev->mutex); |
Dmitry Torokhov | 0fbf87c | 2005-05-29 02:29:25 -0500 | [diff] [blame] | 510 | |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 511 | __input_release_device(handle); |
| 512 | |
Dmitry Torokhov | 0fbf87c | 2005-05-29 02:29:25 -0500 | [diff] [blame] | 513 | if (!--dev->users && dev->close) |
| 514 | dev->close(dev); |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 515 | |
| 516 | if (!--handle->open) { |
| 517 | /* |
Dmitry Torokhov | 82ba56c | 2007-10-13 15:46:55 -0400 | [diff] [blame] | 518 | * synchronize_rcu() makes sure that input_pass_event() |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 519 | * completed and that no more input events are delivered |
| 520 | * through this handle |
| 521 | */ |
Dmitry Torokhov | 82ba56c | 2007-10-13 15:46:55 -0400 | [diff] [blame] | 522 | synchronize_rcu(); |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 523 | } |
Dmitry Torokhov | 0fbf87c | 2005-05-29 02:29:25 -0500 | [diff] [blame] | 524 | |
Jes Sorensen | e676c23 | 2006-02-19 00:21:46 -0500 | [diff] [blame] | 525 | mutex_unlock(&dev->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | } |
Dmitry Torokhov | ca56fe0 | 2006-06-26 01:49:21 -0400 | [diff] [blame] | 527 | EXPORT_SYMBOL(input_close_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 529 | /* |
| 530 | * Prepare device for unregistering |
| 531 | */ |
| 532 | static void input_disconnect_device(struct input_dev *dev) |
| 533 | { |
| 534 | struct input_handle *handle; |
| 535 | int code; |
| 536 | |
| 537 | /* |
| 538 | * Mark device as going away. Note that we take dev->mutex here |
| 539 | * not to protect access to dev->going_away but rather to ensure |
| 540 | * that there are no threads in the middle of input_open_device() |
| 541 | */ |
| 542 | mutex_lock(&dev->mutex); |
Dmitry Torokhov | ffd0db9 | 2009-09-16 01:06:43 -0700 | [diff] [blame] | 543 | dev->going_away = true; |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 544 | mutex_unlock(&dev->mutex); |
| 545 | |
| 546 | spin_lock_irq(&dev->event_lock); |
| 547 | |
| 548 | /* |
| 549 | * Simulate keyup events for all pressed keys so that handlers |
| 550 | * are not left with "stuck" keys. The driver may continue |
| 551 | * generate events even after we done here but they will not |
| 552 | * reach any handlers. |
| 553 | */ |
| 554 | if (is_event_supported(EV_KEY, dev->evbit, EV_MAX)) { |
| 555 | for (code = 0; code <= KEY_MAX; code++) { |
| 556 | if (is_event_supported(code, dev->keybit, KEY_MAX) && |
Dmitry Torokhov | f4f37c8 | 2007-11-04 00:41:12 -0400 | [diff] [blame] | 557 | __test_and_clear_bit(code, dev->key)) { |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 558 | input_pass_event(dev, EV_KEY, code, 0); |
| 559 | } |
| 560 | } |
| 561 | input_pass_event(dev, EV_SYN, SYN_REPORT, 1); |
| 562 | } |
| 563 | |
| 564 | list_for_each_entry(handle, &dev->h_list, d_node) |
| 565 | handle->open = 0; |
| 566 | |
| 567 | spin_unlock_irq(&dev->event_lock); |
| 568 | } |
| 569 | |
Marvin Raaijmakers | c8e4c77 | 2007-03-14 22:50:42 -0400 | [diff] [blame] | 570 | static int input_fetch_keycode(struct input_dev *dev, int scancode) |
| 571 | { |
| 572 | switch (dev->keycodesize) { |
| 573 | case 1: |
| 574 | return ((u8 *)dev->keycode)[scancode]; |
| 575 | |
| 576 | case 2: |
| 577 | return ((u16 *)dev->keycode)[scancode]; |
| 578 | |
| 579 | default: |
| 580 | return ((u32 *)dev->keycode)[scancode]; |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | static int input_default_getkeycode(struct input_dev *dev, |
Dmitry Torokhov | 58b9399 | 2010-03-08 22:37:10 -0800 | [diff] [blame] | 585 | unsigned int scancode, |
| 586 | unsigned int *keycode) |
Marvin Raaijmakers | c8e4c77 | 2007-03-14 22:50:42 -0400 | [diff] [blame] | 587 | { |
| 588 | if (!dev->keycodesize) |
| 589 | return -EINVAL; |
| 590 | |
Dmitry Torokhov | f4f37c8 | 2007-11-04 00:41:12 -0400 | [diff] [blame] | 591 | if (scancode >= dev->keycodemax) |
Marvin Raaijmakers | c8e4c77 | 2007-03-14 22:50:42 -0400 | [diff] [blame] | 592 | return -EINVAL; |
| 593 | |
| 594 | *keycode = input_fetch_keycode(dev, scancode); |
| 595 | |
| 596 | return 0; |
| 597 | } |
| 598 | |
| 599 | static int input_default_setkeycode(struct input_dev *dev, |
Dmitry Torokhov | 58b9399 | 2010-03-08 22:37:10 -0800 | [diff] [blame] | 600 | unsigned int scancode, |
| 601 | unsigned int keycode) |
Marvin Raaijmakers | c8e4c77 | 2007-03-14 22:50:42 -0400 | [diff] [blame] | 602 | { |
| 603 | int old_keycode; |
| 604 | int i; |
| 605 | |
Dmitry Torokhov | f4f37c8 | 2007-11-04 00:41:12 -0400 | [diff] [blame] | 606 | if (scancode >= dev->keycodemax) |
Marvin Raaijmakers | c8e4c77 | 2007-03-14 22:50:42 -0400 | [diff] [blame] | 607 | return -EINVAL; |
| 608 | |
| 609 | if (!dev->keycodesize) |
| 610 | return -EINVAL; |
| 611 | |
| 612 | if (dev->keycodesize < sizeof(keycode) && (keycode >> (dev->keycodesize * 8))) |
| 613 | return -EINVAL; |
| 614 | |
| 615 | switch (dev->keycodesize) { |
| 616 | case 1: { |
| 617 | u8 *k = (u8 *)dev->keycode; |
| 618 | old_keycode = k[scancode]; |
| 619 | k[scancode] = keycode; |
| 620 | break; |
| 621 | } |
| 622 | case 2: { |
| 623 | u16 *k = (u16 *)dev->keycode; |
| 624 | old_keycode = k[scancode]; |
| 625 | k[scancode] = keycode; |
| 626 | break; |
| 627 | } |
| 628 | default: { |
| 629 | u32 *k = (u32 *)dev->keycode; |
| 630 | old_keycode = k[scancode]; |
| 631 | k[scancode] = keycode; |
| 632 | break; |
| 633 | } |
| 634 | } |
| 635 | |
Dmitry Torokhov | 4f93df4 | 2010-01-05 17:56:00 -0800 | [diff] [blame] | 636 | __clear_bit(old_keycode, dev->keybit); |
| 637 | __set_bit(keycode, dev->keybit); |
Marvin Raaijmakers | c8e4c77 | 2007-03-14 22:50:42 -0400 | [diff] [blame] | 638 | |
| 639 | for (i = 0; i < dev->keycodemax; i++) { |
| 640 | if (input_fetch_keycode(dev, i) == old_keycode) { |
Dmitry Torokhov | 4f93df4 | 2010-01-05 17:56:00 -0800 | [diff] [blame] | 641 | __set_bit(old_keycode, dev->keybit); |
Marvin Raaijmakers | c8e4c77 | 2007-03-14 22:50:42 -0400 | [diff] [blame] | 642 | break; /* Setting the bit twice is useless, so break */ |
| 643 | } |
| 644 | } |
| 645 | |
| 646 | return 0; |
| 647 | } |
| 648 | |
Dmitry Torokhov | f4f37c8 | 2007-11-04 00:41:12 -0400 | [diff] [blame] | 649 | /** |
| 650 | * input_get_keycode - retrieve keycode currently mapped to a given scancode |
| 651 | * @dev: input device which keymap is being queried |
| 652 | * @scancode: scancode (or its equivalent for device in question) for which |
| 653 | * keycode is needed |
| 654 | * @keycode: result |
| 655 | * |
| 656 | * This function should be called by anyone interested in retrieving current |
| 657 | * keymap. Presently keyboard and evdev handlers use it. |
| 658 | */ |
Dmitry Torokhov | 58b9399 | 2010-03-08 22:37:10 -0800 | [diff] [blame] | 659 | int input_get_keycode(struct input_dev *dev, |
| 660 | unsigned int scancode, unsigned int *keycode) |
Dmitry Torokhov | f4f37c8 | 2007-11-04 00:41:12 -0400 | [diff] [blame] | 661 | { |
Dmitry Torokhov | f4f37c8 | 2007-11-04 00:41:12 -0400 | [diff] [blame] | 662 | return dev->getkeycode(dev, scancode, keycode); |
| 663 | } |
| 664 | EXPORT_SYMBOL(input_get_keycode); |
| 665 | |
| 666 | /** |
| 667 | * input_get_keycode - assign new keycode to a given scancode |
| 668 | * @dev: input device which keymap is being updated |
| 669 | * @scancode: scancode (or its equivalent for device in question) |
| 670 | * @keycode: new keycode to be assigned to the scancode |
| 671 | * |
| 672 | * This function should be called by anyone needing to update current |
| 673 | * keymap. Presently keyboard and evdev handlers use it. |
| 674 | */ |
Dmitry Torokhov | 58b9399 | 2010-03-08 22:37:10 -0800 | [diff] [blame] | 675 | int input_set_keycode(struct input_dev *dev, |
| 676 | unsigned int scancode, unsigned int keycode) |
Dmitry Torokhov | f4f37c8 | 2007-11-04 00:41:12 -0400 | [diff] [blame] | 677 | { |
| 678 | unsigned long flags; |
| 679 | int old_keycode; |
| 680 | int retval; |
| 681 | |
Dmitry Torokhov | 58b9399 | 2010-03-08 22:37:10 -0800 | [diff] [blame] | 682 | if (keycode > KEY_MAX) |
Dmitry Torokhov | f4f37c8 | 2007-11-04 00:41:12 -0400 | [diff] [blame] | 683 | return -EINVAL; |
| 684 | |
| 685 | spin_lock_irqsave(&dev->event_lock, flags); |
| 686 | |
| 687 | retval = dev->getkeycode(dev, scancode, &old_keycode); |
| 688 | if (retval) |
| 689 | goto out; |
| 690 | |
| 691 | retval = dev->setkeycode(dev, scancode, keycode); |
| 692 | if (retval) |
| 693 | goto out; |
| 694 | |
Dmitry Torokhov | 4f93df4 | 2010-01-05 17:56:00 -0800 | [diff] [blame] | 695 | /* Make sure KEY_RESERVED did not get enabled. */ |
| 696 | __clear_bit(KEY_RESERVED, dev->keybit); |
| 697 | |
Dmitry Torokhov | f4f37c8 | 2007-11-04 00:41:12 -0400 | [diff] [blame] | 698 | /* |
| 699 | * Simulate keyup event if keycode is not present |
| 700 | * in the keymap anymore |
| 701 | */ |
| 702 | if (test_bit(EV_KEY, dev->evbit) && |
| 703 | !is_event_supported(old_keycode, dev->keybit, KEY_MAX) && |
| 704 | __test_and_clear_bit(old_keycode, dev->key)) { |
| 705 | |
| 706 | input_pass_event(dev, EV_KEY, old_keycode, 0); |
| 707 | if (dev->sync) |
| 708 | input_pass_event(dev, EV_SYN, SYN_REPORT, 1); |
| 709 | } |
| 710 | |
| 711 | out: |
| 712 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 713 | |
| 714 | return retval; |
| 715 | } |
| 716 | EXPORT_SYMBOL(input_set_keycode); |
Marvin Raaijmakers | c8e4c77 | 2007-03-14 22:50:42 -0400 | [diff] [blame] | 717 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | #define MATCH_BIT(bit, max) \ |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 719 | for (i = 0; i < BITS_TO_LONGS(max); i++) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | if ((id->bit[i] & dev->bit[i]) != id->bit[i]) \ |
| 721 | break; \ |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 722 | if (i != BITS_TO_LONGS(max)) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | continue; |
| 724 | |
Dmitry Torokhov | 0b7024ac | 2010-02-02 21:08:26 -0800 | [diff] [blame] | 725 | static const struct input_device_id *input_match_device(struct input_handler *handler, |
Dmitry Torokhov | 66e6611 | 2006-09-14 01:31:59 -0400 | [diff] [blame] | 726 | struct input_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | { |
Dmitry Torokhov | 0b7024ac | 2010-02-02 21:08:26 -0800 | [diff] [blame] | 728 | const struct input_device_id *id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | int i; |
| 730 | |
Dmitry Torokhov | 0b7024ac | 2010-02-02 21:08:26 -0800 | [diff] [blame] | 731 | for (id = handler->id_table; id->flags || id->driver_info; id++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | |
| 733 | if (id->flags & INPUT_DEVICE_ID_MATCH_BUS) |
Dmitry Torokhov | ddc5d34 | 2006-04-26 00:14:19 -0400 | [diff] [blame] | 734 | if (id->bustype != dev->id.bustype) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | continue; |
| 736 | |
| 737 | if (id->flags & INPUT_DEVICE_ID_MATCH_VENDOR) |
Dmitry Torokhov | ddc5d34 | 2006-04-26 00:14:19 -0400 | [diff] [blame] | 738 | if (id->vendor != dev->id.vendor) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | continue; |
| 740 | |
| 741 | if (id->flags & INPUT_DEVICE_ID_MATCH_PRODUCT) |
Dmitry Torokhov | ddc5d34 | 2006-04-26 00:14:19 -0400 | [diff] [blame] | 742 | if (id->product != dev->id.product) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | continue; |
| 744 | |
| 745 | if (id->flags & INPUT_DEVICE_ID_MATCH_VERSION) |
Dmitry Torokhov | ddc5d34 | 2006-04-26 00:14:19 -0400 | [diff] [blame] | 746 | if (id->version != dev->id.version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | continue; |
| 748 | |
| 749 | MATCH_BIT(evbit, EV_MAX); |
| 750 | MATCH_BIT(keybit, KEY_MAX); |
| 751 | MATCH_BIT(relbit, REL_MAX); |
| 752 | MATCH_BIT(absbit, ABS_MAX); |
| 753 | MATCH_BIT(mscbit, MSC_MAX); |
| 754 | MATCH_BIT(ledbit, LED_MAX); |
| 755 | MATCH_BIT(sndbit, SND_MAX); |
| 756 | MATCH_BIT(ffbit, FF_MAX); |
Dmitry Torokhov | ff13f98 | 2005-09-24 02:02:29 -0500 | [diff] [blame] | 757 | MATCH_BIT(swbit, SW_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | |
Dmitry Torokhov | 0b7024ac | 2010-02-02 21:08:26 -0800 | [diff] [blame] | 759 | if (!handler->match || handler->match(handler, dev)) |
| 760 | return id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | return NULL; |
| 764 | } |
| 765 | |
Dmitry Torokhov | 5b2a082 | 2007-04-12 01:29:46 -0400 | [diff] [blame] | 766 | static int input_attach_handler(struct input_dev *dev, struct input_handler *handler) |
| 767 | { |
| 768 | const struct input_device_id *id; |
| 769 | int error; |
| 770 | |
Dmitry Torokhov | 0b7024ac | 2010-02-02 21:08:26 -0800 | [diff] [blame] | 771 | id = input_match_device(handler, dev); |
Dmitry Torokhov | 5b2a082 | 2007-04-12 01:29:46 -0400 | [diff] [blame] | 772 | if (!id) |
| 773 | return -ENODEV; |
| 774 | |
| 775 | error = handler->connect(handler, dev, id); |
| 776 | if (error && error != -ENODEV) |
| 777 | printk(KERN_ERR |
| 778 | "input: failed to attach handler %s to device %s, " |
| 779 | "error: %d\n", |
Dmitry Torokhov | 9657d75 | 2007-06-14 23:32:24 -0400 | [diff] [blame] | 780 | handler->name, kobject_name(&dev->dev.kobj), error); |
Dmitry Torokhov | 5b2a082 | 2007-04-12 01:29:46 -0400 | [diff] [blame] | 781 | |
| 782 | return error; |
| 783 | } |
| 784 | |
Dmitry Torokhov | 15e184a | 2010-01-11 00:05:43 -0800 | [diff] [blame] | 785 | #ifdef CONFIG_COMPAT |
| 786 | |
| 787 | static int input_bits_to_string(char *buf, int buf_size, |
| 788 | unsigned long bits, bool skip_empty) |
| 789 | { |
| 790 | int len = 0; |
| 791 | |
| 792 | if (INPUT_COMPAT_TEST) { |
| 793 | u32 dword = bits >> 32; |
| 794 | if (dword || !skip_empty) |
| 795 | len += snprintf(buf, buf_size, "%x ", dword); |
| 796 | |
| 797 | dword = bits & 0xffffffffUL; |
| 798 | if (dword || !skip_empty || len) |
| 799 | len += snprintf(buf + len, max(buf_size - len, 0), |
| 800 | "%x", dword); |
| 801 | } else { |
| 802 | if (bits || !skip_empty) |
| 803 | len += snprintf(buf, buf_size, "%lx", bits); |
| 804 | } |
| 805 | |
| 806 | return len; |
| 807 | } |
| 808 | |
| 809 | #else /* !CONFIG_COMPAT */ |
| 810 | |
| 811 | static int input_bits_to_string(char *buf, int buf_size, |
| 812 | unsigned long bits, bool skip_empty) |
| 813 | { |
| 814 | return bits || !skip_empty ? |
| 815 | snprintf(buf, buf_size, "%lx", bits) : 0; |
| 816 | } |
| 817 | |
| 818 | #endif |
Dmitry Torokhov | 5b2a082 | 2007-04-12 01:29:46 -0400 | [diff] [blame] | 819 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | #ifdef CONFIG_PROC_FS |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 821 | |
| 822 | static struct proc_dir_entry *proc_bus_input_dir; |
| 823 | static DECLARE_WAIT_QUEUE_HEAD(input_devices_poll_wait); |
| 824 | static int input_devices_state; |
| 825 | |
| 826 | static inline void input_wakeup_procfs_readers(void) |
| 827 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | input_devices_state++; |
| 829 | wake_up(&input_devices_poll_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | } |
| 831 | |
Dmitry Torokhov | 969b21c | 2006-04-02 00:09:34 -0500 | [diff] [blame] | 832 | static unsigned int input_proc_devices_poll(struct file *file, poll_table *wait) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | { |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 834 | poll_wait(file, &input_devices_poll_wait, wait); |
Dmitry Torokhov | fa88661 | 2009-03-04 00:52:20 -0800 | [diff] [blame] | 835 | if (file->f_version != input_devices_state) { |
| 836 | file->f_version = input_devices_state; |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 837 | return POLLIN | POLLRDNORM; |
Dmitry Torokhov | fa88661 | 2009-03-04 00:52:20 -0800 | [diff] [blame] | 838 | } |
Dmitry Torokhov | 1e0afb2 | 2006-06-26 01:48:47 -0400 | [diff] [blame] | 839 | |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 840 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | } |
| 842 | |
Dmitry Torokhov | 1572ca2 | 2009-10-13 23:37:30 -0700 | [diff] [blame] | 843 | union input_seq_state { |
| 844 | struct { |
| 845 | unsigned short pos; |
| 846 | bool mutex_acquired; |
| 847 | }; |
| 848 | void *p; |
| 849 | }; |
| 850 | |
Dmitry Torokhov | 969b21c | 2006-04-02 00:09:34 -0500 | [diff] [blame] | 851 | static void *input_devices_seq_start(struct seq_file *seq, loff_t *pos) |
| 852 | { |
Dmitry Torokhov | 1572ca2 | 2009-10-13 23:37:30 -0700 | [diff] [blame] | 853 | union input_seq_state *state = (union input_seq_state *)&seq->private; |
| 854 | int error; |
| 855 | |
| 856 | /* We need to fit into seq->private pointer */ |
| 857 | BUILD_BUG_ON(sizeof(union input_seq_state) != sizeof(seq->private)); |
| 858 | |
| 859 | error = mutex_lock_interruptible(&input_mutex); |
| 860 | if (error) { |
| 861 | state->mutex_acquired = false; |
| 862 | return ERR_PTR(error); |
| 863 | } |
| 864 | |
| 865 | state->mutex_acquired = true; |
Dmitry Torokhov | 969b21c | 2006-04-02 00:09:34 -0500 | [diff] [blame] | 866 | |
Pavel Emelianov | ad5d972 | 2007-07-18 00:38:32 -0400 | [diff] [blame] | 867 | return seq_list_start(&input_dev_list, *pos); |
Dmitry Torokhov | 969b21c | 2006-04-02 00:09:34 -0500 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | static void *input_devices_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
| 871 | { |
Pavel Emelianov | ad5d972 | 2007-07-18 00:38:32 -0400 | [diff] [blame] | 872 | return seq_list_next(v, &input_dev_list, pos); |
Dmitry Torokhov | 969b21c | 2006-04-02 00:09:34 -0500 | [diff] [blame] | 873 | } |
| 874 | |
Dmitry Torokhov | 1572ca2 | 2009-10-13 23:37:30 -0700 | [diff] [blame] | 875 | static void input_seq_stop(struct seq_file *seq, void *v) |
Dmitry Torokhov | 969b21c | 2006-04-02 00:09:34 -0500 | [diff] [blame] | 876 | { |
Dmitry Torokhov | 1572ca2 | 2009-10-13 23:37:30 -0700 | [diff] [blame] | 877 | union input_seq_state *state = (union input_seq_state *)&seq->private; |
| 878 | |
| 879 | if (state->mutex_acquired) |
| 880 | mutex_unlock(&input_mutex); |
Dmitry Torokhov | 969b21c | 2006-04-02 00:09:34 -0500 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | static void input_seq_print_bitmap(struct seq_file *seq, const char *name, |
| 884 | unsigned long *bitmap, int max) |
| 885 | { |
| 886 | int i; |
Dmitry Torokhov | 15e184a | 2010-01-11 00:05:43 -0800 | [diff] [blame] | 887 | bool skip_empty = true; |
| 888 | char buf[18]; |
Dmitry Torokhov | 969b21c | 2006-04-02 00:09:34 -0500 | [diff] [blame] | 889 | |
| 890 | seq_printf(seq, "B: %s=", name); |
Dmitry Torokhov | 15e184a | 2010-01-11 00:05:43 -0800 | [diff] [blame] | 891 | |
| 892 | for (i = BITS_TO_LONGS(max) - 1; i >= 0; i--) { |
| 893 | if (input_bits_to_string(buf, sizeof(buf), |
| 894 | bitmap[i], skip_empty)) { |
| 895 | skip_empty = false; |
| 896 | seq_printf(seq, "%s%s", buf, i > 0 ? " " : ""); |
| 897 | } |
| 898 | } |
| 899 | |
| 900 | /* |
| 901 | * If no output was produced print a single 0. |
| 902 | */ |
| 903 | if (skip_empty) |
| 904 | seq_puts(seq, "0"); |
| 905 | |
Dmitry Torokhov | 969b21c | 2006-04-02 00:09:34 -0500 | [diff] [blame] | 906 | seq_putc(seq, '\n'); |
| 907 | } |
| 908 | |
| 909 | static int input_devices_seq_show(struct seq_file *seq, void *v) |
| 910 | { |
| 911 | struct input_dev *dev = container_of(v, struct input_dev, node); |
Dmitry Torokhov | 9657d75 | 2007-06-14 23:32:24 -0400 | [diff] [blame] | 912 | const char *path = kobject_get_path(&dev->dev.kobj, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | struct input_handle *handle; |
| 914 | |
Dmitry Torokhov | 969b21c | 2006-04-02 00:09:34 -0500 | [diff] [blame] | 915 | seq_printf(seq, "I: Bus=%04x Vendor=%04x Product=%04x Version=%04x\n", |
| 916 | dev->id.bustype, dev->id.vendor, dev->id.product, dev->id.version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | |
Dmitry Torokhov | 969b21c | 2006-04-02 00:09:34 -0500 | [diff] [blame] | 918 | seq_printf(seq, "N: Name=\"%s\"\n", dev->name ? dev->name : ""); |
| 919 | seq_printf(seq, "P: Phys=%s\n", dev->phys ? dev->phys : ""); |
| 920 | seq_printf(seq, "S: Sysfs=%s\n", path ? path : ""); |
Dmitry Torokhov | 15e03ae | 2007-03-07 23:20:17 -0500 | [diff] [blame] | 921 | seq_printf(seq, "U: Uniq=%s\n", dev->uniq ? dev->uniq : ""); |
Dmitry Torokhov | 969b21c | 2006-04-02 00:09:34 -0500 | [diff] [blame] | 922 | seq_printf(seq, "H: Handlers="); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | |
Dmitry Torokhov | 969b21c | 2006-04-02 00:09:34 -0500 | [diff] [blame] | 924 | list_for_each_entry(handle, &dev->h_list, d_node) |
| 925 | seq_printf(seq, "%s ", handle->name); |
| 926 | seq_putc(seq, '\n'); |
Dmitry Torokhov | 051b2fe | 2005-09-15 02:01:54 -0500 | [diff] [blame] | 927 | |
Dmitry Torokhov | 969b21c | 2006-04-02 00:09:34 -0500 | [diff] [blame] | 928 | input_seq_print_bitmap(seq, "EV", dev->evbit, EV_MAX); |
| 929 | if (test_bit(EV_KEY, dev->evbit)) |
| 930 | input_seq_print_bitmap(seq, "KEY", dev->keybit, KEY_MAX); |
| 931 | if (test_bit(EV_REL, dev->evbit)) |
| 932 | input_seq_print_bitmap(seq, "REL", dev->relbit, REL_MAX); |
| 933 | if (test_bit(EV_ABS, dev->evbit)) |
| 934 | input_seq_print_bitmap(seq, "ABS", dev->absbit, ABS_MAX); |
| 935 | if (test_bit(EV_MSC, dev->evbit)) |
| 936 | input_seq_print_bitmap(seq, "MSC", dev->mscbit, MSC_MAX); |
| 937 | if (test_bit(EV_LED, dev->evbit)) |
| 938 | input_seq_print_bitmap(seq, "LED", dev->ledbit, LED_MAX); |
| 939 | if (test_bit(EV_SND, dev->evbit)) |
| 940 | input_seq_print_bitmap(seq, "SND", dev->sndbit, SND_MAX); |
| 941 | if (test_bit(EV_FF, dev->evbit)) |
| 942 | input_seq_print_bitmap(seq, "FF", dev->ffbit, FF_MAX); |
| 943 | if (test_bit(EV_SW, dev->evbit)) |
| 944 | input_seq_print_bitmap(seq, "SW", dev->swbit, SW_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | |
Dmitry Torokhov | 969b21c | 2006-04-02 00:09:34 -0500 | [diff] [blame] | 946 | seq_putc(seq, '\n'); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | |
Dmitry Torokhov | 969b21c | 2006-04-02 00:09:34 -0500 | [diff] [blame] | 948 | kfree(path); |
| 949 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | } |
| 951 | |
Jan Engelhardt | cec69c3 | 2008-01-31 00:43:32 -0500 | [diff] [blame] | 952 | static const struct seq_operations input_devices_seq_ops = { |
Dmitry Torokhov | 969b21c | 2006-04-02 00:09:34 -0500 | [diff] [blame] | 953 | .start = input_devices_seq_start, |
| 954 | .next = input_devices_seq_next, |
Dmitry Torokhov | 1572ca2 | 2009-10-13 23:37:30 -0700 | [diff] [blame] | 955 | .stop = input_seq_stop, |
Dmitry Torokhov | 969b21c | 2006-04-02 00:09:34 -0500 | [diff] [blame] | 956 | .show = input_devices_seq_show, |
| 957 | }; |
| 958 | |
| 959 | static int input_proc_devices_open(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | { |
Dmitry Torokhov | 969b21c | 2006-04-02 00:09:34 -0500 | [diff] [blame] | 961 | return seq_open(file, &input_devices_seq_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | } |
| 963 | |
Arjan van de Ven | 2b8693c | 2007-02-12 00:55:32 -0800 | [diff] [blame] | 964 | static const struct file_operations input_devices_fileops = { |
Dmitry Torokhov | 969b21c | 2006-04-02 00:09:34 -0500 | [diff] [blame] | 965 | .owner = THIS_MODULE, |
| 966 | .open = input_proc_devices_open, |
| 967 | .poll = input_proc_devices_poll, |
| 968 | .read = seq_read, |
| 969 | .llseek = seq_lseek, |
| 970 | .release = seq_release, |
| 971 | }; |
| 972 | |
| 973 | static void *input_handlers_seq_start(struct seq_file *seq, loff_t *pos) |
| 974 | { |
Dmitry Torokhov | 1572ca2 | 2009-10-13 23:37:30 -0700 | [diff] [blame] | 975 | union input_seq_state *state = (union input_seq_state *)&seq->private; |
| 976 | int error; |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 977 | |
Dmitry Torokhov | 1572ca2 | 2009-10-13 23:37:30 -0700 | [diff] [blame] | 978 | /* We need to fit into seq->private pointer */ |
| 979 | BUILD_BUG_ON(sizeof(union input_seq_state) != sizeof(seq->private)); |
| 980 | |
| 981 | error = mutex_lock_interruptible(&input_mutex); |
| 982 | if (error) { |
| 983 | state->mutex_acquired = false; |
| 984 | return ERR_PTR(error); |
| 985 | } |
| 986 | |
| 987 | state->mutex_acquired = true; |
| 988 | state->pos = *pos; |
| 989 | |
Pavel Emelianov | ad5d972 | 2007-07-18 00:38:32 -0400 | [diff] [blame] | 990 | return seq_list_start(&input_handler_list, *pos); |
Dmitry Torokhov | 969b21c | 2006-04-02 00:09:34 -0500 | [diff] [blame] | 991 | } |
| 992 | |
| 993 | static void *input_handlers_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
| 994 | { |
Dmitry Torokhov | 1572ca2 | 2009-10-13 23:37:30 -0700 | [diff] [blame] | 995 | union input_seq_state *state = (union input_seq_state *)&seq->private; |
Dmitry Torokhov | 969b21c | 2006-04-02 00:09:34 -0500 | [diff] [blame] | 996 | |
Dmitry Torokhov | 1572ca2 | 2009-10-13 23:37:30 -0700 | [diff] [blame] | 997 | state->pos = *pos + 1; |
| 998 | return seq_list_next(v, &input_handler_list, pos); |
Dmitry Torokhov | 969b21c | 2006-04-02 00:09:34 -0500 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | static int input_handlers_seq_show(struct seq_file *seq, void *v) |
| 1002 | { |
| 1003 | struct input_handler *handler = container_of(v, struct input_handler, node); |
Dmitry Torokhov | 1572ca2 | 2009-10-13 23:37:30 -0700 | [diff] [blame] | 1004 | union input_seq_state *state = (union input_seq_state *)&seq->private; |
Dmitry Torokhov | 969b21c | 2006-04-02 00:09:34 -0500 | [diff] [blame] | 1005 | |
Dmitry Torokhov | 1572ca2 | 2009-10-13 23:37:30 -0700 | [diff] [blame] | 1006 | seq_printf(seq, "N: Number=%u Name=%s", state->pos, handler->name); |
Dmitry Torokhov | ef7995f | 2010-01-29 23:59:12 -0800 | [diff] [blame] | 1007 | if (handler->filter) |
| 1008 | seq_puts(seq, " (filter)"); |
Dmitry Torokhov | 969b21c | 2006-04-02 00:09:34 -0500 | [diff] [blame] | 1009 | if (handler->fops) |
| 1010 | seq_printf(seq, " Minor=%d", handler->minor); |
| 1011 | seq_putc(seq, '\n'); |
| 1012 | |
| 1013 | return 0; |
| 1014 | } |
Dmitry Torokhov | 1572ca2 | 2009-10-13 23:37:30 -0700 | [diff] [blame] | 1015 | |
Jan Engelhardt | cec69c3 | 2008-01-31 00:43:32 -0500 | [diff] [blame] | 1016 | static const struct seq_operations input_handlers_seq_ops = { |
Dmitry Torokhov | 969b21c | 2006-04-02 00:09:34 -0500 | [diff] [blame] | 1017 | .start = input_handlers_seq_start, |
| 1018 | .next = input_handlers_seq_next, |
Dmitry Torokhov | 1572ca2 | 2009-10-13 23:37:30 -0700 | [diff] [blame] | 1019 | .stop = input_seq_stop, |
Dmitry Torokhov | 969b21c | 2006-04-02 00:09:34 -0500 | [diff] [blame] | 1020 | .show = input_handlers_seq_show, |
| 1021 | }; |
| 1022 | |
| 1023 | static int input_proc_handlers_open(struct inode *inode, struct file *file) |
| 1024 | { |
| 1025 | return seq_open(file, &input_handlers_seq_ops); |
| 1026 | } |
| 1027 | |
Arjan van de Ven | 2b8693c | 2007-02-12 00:55:32 -0800 | [diff] [blame] | 1028 | static const struct file_operations input_handlers_fileops = { |
Dmitry Torokhov | 969b21c | 2006-04-02 00:09:34 -0500 | [diff] [blame] | 1029 | .owner = THIS_MODULE, |
| 1030 | .open = input_proc_handlers_open, |
| 1031 | .read = seq_read, |
| 1032 | .llseek = seq_lseek, |
| 1033 | .release = seq_release, |
| 1034 | }; |
Luke Kosewski | e334016fc | 2005-06-01 02:39:28 -0500 | [diff] [blame] | 1035 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | static int __init input_proc_init(void) |
| 1037 | { |
| 1038 | struct proc_dir_entry *entry; |
| 1039 | |
Alexey Dobriyan | 9c37066 | 2008-04-29 01:01:41 -0700 | [diff] [blame] | 1040 | proc_bus_input_dir = proc_mkdir("bus/input", NULL); |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1041 | if (!proc_bus_input_dir) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | return -ENOMEM; |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1043 | |
Denis V. Lunev | c7705f3 | 2008-04-29 01:02:35 -0700 | [diff] [blame] | 1044 | entry = proc_create("devices", 0, proc_bus_input_dir, |
| 1045 | &input_devices_fileops); |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1046 | if (!entry) |
| 1047 | goto fail1; |
| 1048 | |
Denis V. Lunev | c7705f3 | 2008-04-29 01:02:35 -0700 | [diff] [blame] | 1049 | entry = proc_create("handlers", 0, proc_bus_input_dir, |
| 1050 | &input_handlers_fileops); |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1051 | if (!entry) |
| 1052 | goto fail2; |
| 1053 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | return 0; |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1055 | |
| 1056 | fail2: remove_proc_entry("devices", proc_bus_input_dir); |
Alexey Dobriyan | 9c37066 | 2008-04-29 01:01:41 -0700 | [diff] [blame] | 1057 | fail1: remove_proc_entry("bus/input", NULL); |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1058 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | } |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1060 | |
Andrew Morton | beffbdc | 2005-07-01 23:54:30 -0500 | [diff] [blame] | 1061 | static void input_proc_exit(void) |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1062 | { |
| 1063 | remove_proc_entry("devices", proc_bus_input_dir); |
| 1064 | remove_proc_entry("handlers", proc_bus_input_dir); |
Alexey Dobriyan | 9c37066 | 2008-04-29 01:01:41 -0700 | [diff] [blame] | 1065 | remove_proc_entry("bus/input", NULL); |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1066 | } |
| 1067 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | #else /* !CONFIG_PROC_FS */ |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1069 | static inline void input_wakeup_procfs_readers(void) { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | static inline int input_proc_init(void) { return 0; } |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1071 | static inline void input_proc_exit(void) { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | #endif |
| 1073 | |
Dmitry Torokhov | 9657d75 | 2007-06-14 23:32:24 -0400 | [diff] [blame] | 1074 | #define INPUT_DEV_STRING_ATTR_SHOW(name) \ |
| 1075 | static ssize_t input_dev_show_##name(struct device *dev, \ |
| 1076 | struct device_attribute *attr, \ |
| 1077 | char *buf) \ |
| 1078 | { \ |
| 1079 | struct input_dev *input_dev = to_input_dev(dev); \ |
| 1080 | \ |
| 1081 | return scnprintf(buf, PAGE_SIZE, "%s\n", \ |
| 1082 | input_dev->name ? input_dev->name : ""); \ |
| 1083 | } \ |
| 1084 | static DEVICE_ATTR(name, S_IRUGO, input_dev_show_##name, NULL) |
Dmitry Torokhov | 5c1e9a6 | 2005-09-15 02:01:55 -0500 | [diff] [blame] | 1085 | |
| 1086 | INPUT_DEV_STRING_ATTR_SHOW(name); |
| 1087 | INPUT_DEV_STRING_ATTR_SHOW(phys); |
| 1088 | INPUT_DEV_STRING_ATTR_SHOW(uniq); |
| 1089 | |
Dmitry Torokhov | ac648a6 | 2006-04-02 00:09:51 -0500 | [diff] [blame] | 1090 | static int input_print_modalias_bits(char *buf, int size, |
| 1091 | char name, unsigned long *bm, |
| 1092 | unsigned int min_bit, unsigned int max_bit) |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 1093 | { |
Dmitry Torokhov | ac648a6 | 2006-04-02 00:09:51 -0500 | [diff] [blame] | 1094 | int len = 0, i; |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 1095 | |
Dmitry Torokhov | ac648a6 | 2006-04-02 00:09:51 -0500 | [diff] [blame] | 1096 | len += snprintf(buf, max(size, 0), "%c", name); |
| 1097 | for (i = min_bit; i < max_bit; i++) |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 1098 | if (bm[BIT_WORD(i)] & BIT_MASK(i)) |
Dmitry Torokhov | ac648a6 | 2006-04-02 00:09:51 -0500 | [diff] [blame] | 1099 | len += snprintf(buf + len, max(size - len, 0), "%X,", i); |
Kay Sievers | bd37e5a | 2006-01-05 13:19:55 +0100 | [diff] [blame] | 1100 | return len; |
| 1101 | } |
| 1102 | |
Dmitry Torokhov | 2db6687 | 2006-04-02 00:09:26 -0500 | [diff] [blame] | 1103 | static int input_print_modalias(char *buf, int size, struct input_dev *id, |
| 1104 | int add_cr) |
Kay Sievers | bd37e5a | 2006-01-05 13:19:55 +0100 | [diff] [blame] | 1105 | { |
| 1106 | int len; |
| 1107 | |
Dmitry Torokhov | ac648a6 | 2006-04-02 00:09:51 -0500 | [diff] [blame] | 1108 | len = snprintf(buf, max(size, 0), |
| 1109 | "input:b%04Xv%04Xp%04Xe%04X-", |
| 1110 | id->id.bustype, id->id.vendor, |
| 1111 | id->id.product, id->id.version); |
Kay Sievers | bd37e5a | 2006-01-05 13:19:55 +0100 | [diff] [blame] | 1112 | |
Dmitry Torokhov | ac648a6 | 2006-04-02 00:09:51 -0500 | [diff] [blame] | 1113 | len += input_print_modalias_bits(buf + len, size - len, |
| 1114 | 'e', id->evbit, 0, EV_MAX); |
| 1115 | len += input_print_modalias_bits(buf + len, size - len, |
| 1116 | 'k', id->keybit, KEY_MIN_INTERESTING, KEY_MAX); |
| 1117 | len += input_print_modalias_bits(buf + len, size - len, |
| 1118 | 'r', id->relbit, 0, REL_MAX); |
| 1119 | len += input_print_modalias_bits(buf + len, size - len, |
| 1120 | 'a', id->absbit, 0, ABS_MAX); |
| 1121 | len += input_print_modalias_bits(buf + len, size - len, |
| 1122 | 'm', id->mscbit, 0, MSC_MAX); |
| 1123 | len += input_print_modalias_bits(buf + len, size - len, |
| 1124 | 'l', id->ledbit, 0, LED_MAX); |
| 1125 | len += input_print_modalias_bits(buf + len, size - len, |
| 1126 | 's', id->sndbit, 0, SND_MAX); |
| 1127 | len += input_print_modalias_bits(buf + len, size - len, |
| 1128 | 'f', id->ffbit, 0, FF_MAX); |
| 1129 | len += input_print_modalias_bits(buf + len, size - len, |
| 1130 | 'w', id->swbit, 0, SW_MAX); |
Dmitry Torokhov | 2db6687 | 2006-04-02 00:09:26 -0500 | [diff] [blame] | 1131 | |
| 1132 | if (add_cr) |
Dmitry Torokhov | ac648a6 | 2006-04-02 00:09:51 -0500 | [diff] [blame] | 1133 | len += snprintf(buf + len, max(size - len, 0), "\n"); |
Dmitry Torokhov | 2db6687 | 2006-04-02 00:09:26 -0500 | [diff] [blame] | 1134 | |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 1135 | return len; |
| 1136 | } |
| 1137 | |
Dmitry Torokhov | 9657d75 | 2007-06-14 23:32:24 -0400 | [diff] [blame] | 1138 | static ssize_t input_dev_show_modalias(struct device *dev, |
| 1139 | struct device_attribute *attr, |
| 1140 | char *buf) |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 1141 | { |
| 1142 | struct input_dev *id = to_input_dev(dev); |
Kay Sievers | bd37e5a | 2006-01-05 13:19:55 +0100 | [diff] [blame] | 1143 | ssize_t len; |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 1144 | |
Dmitry Torokhov | 2db6687 | 2006-04-02 00:09:26 -0500 | [diff] [blame] | 1145 | len = input_print_modalias(buf, PAGE_SIZE, id, 1); |
| 1146 | |
Richard Purdie | 8a3cf45 | 2006-06-26 01:48:21 -0400 | [diff] [blame] | 1147 | return min_t(int, len, PAGE_SIZE); |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 1148 | } |
Dmitry Torokhov | 9657d75 | 2007-06-14 23:32:24 -0400 | [diff] [blame] | 1149 | static DEVICE_ATTR(modalias, S_IRUGO, input_dev_show_modalias, NULL); |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 1150 | |
Greg Kroah-Hartman | 629b77a | 2005-10-27 22:25:43 -0700 | [diff] [blame] | 1151 | static struct attribute *input_dev_attrs[] = { |
Dmitry Torokhov | 9657d75 | 2007-06-14 23:32:24 -0400 | [diff] [blame] | 1152 | &dev_attr_name.attr, |
| 1153 | &dev_attr_phys.attr, |
| 1154 | &dev_attr_uniq.attr, |
| 1155 | &dev_attr_modalias.attr, |
Greg Kroah-Hartman | 629b77a | 2005-10-27 22:25:43 -0700 | [diff] [blame] | 1156 | NULL |
| 1157 | }; |
| 1158 | |
Dmitry Torokhov | bd0ef23 | 2005-11-20 00:56:31 -0500 | [diff] [blame] | 1159 | static struct attribute_group input_dev_attr_group = { |
Greg Kroah-Hartman | 629b77a | 2005-10-27 22:25:43 -0700 | [diff] [blame] | 1160 | .attrs = input_dev_attrs, |
Dmitry Torokhov | 5c1e9a6 | 2005-09-15 02:01:55 -0500 | [diff] [blame] | 1161 | }; |
| 1162 | |
Dmitry Torokhov | 9657d75 | 2007-06-14 23:32:24 -0400 | [diff] [blame] | 1163 | #define INPUT_DEV_ID_ATTR(name) \ |
| 1164 | static ssize_t input_dev_show_id_##name(struct device *dev, \ |
| 1165 | struct device_attribute *attr, \ |
| 1166 | char *buf) \ |
| 1167 | { \ |
| 1168 | struct input_dev *input_dev = to_input_dev(dev); \ |
| 1169 | return scnprintf(buf, PAGE_SIZE, "%04x\n", input_dev->id.name); \ |
| 1170 | } \ |
| 1171 | static DEVICE_ATTR(name, S_IRUGO, input_dev_show_id_##name, NULL) |
Dmitry Torokhov | 5c1e9a6 | 2005-09-15 02:01:55 -0500 | [diff] [blame] | 1172 | |
| 1173 | INPUT_DEV_ID_ATTR(bustype); |
| 1174 | INPUT_DEV_ID_ATTR(vendor); |
| 1175 | INPUT_DEV_ID_ATTR(product); |
| 1176 | INPUT_DEV_ID_ATTR(version); |
| 1177 | |
| 1178 | static struct attribute *input_dev_id_attrs[] = { |
Dmitry Torokhov | 9657d75 | 2007-06-14 23:32:24 -0400 | [diff] [blame] | 1179 | &dev_attr_bustype.attr, |
| 1180 | &dev_attr_vendor.attr, |
| 1181 | &dev_attr_product.attr, |
| 1182 | &dev_attr_version.attr, |
Dmitry Torokhov | 5c1e9a6 | 2005-09-15 02:01:55 -0500 | [diff] [blame] | 1183 | NULL |
| 1184 | }; |
| 1185 | |
| 1186 | static struct attribute_group input_dev_id_attr_group = { |
| 1187 | .name = "id", |
| 1188 | .attrs = input_dev_id_attrs, |
| 1189 | }; |
| 1190 | |
Dmitry Torokhov | 969b21c | 2006-04-02 00:09:34 -0500 | [diff] [blame] | 1191 | static int input_print_bitmap(char *buf, int buf_size, unsigned long *bitmap, |
| 1192 | int max, int add_cr) |
| 1193 | { |
| 1194 | int i; |
| 1195 | int len = 0; |
Dmitry Torokhov | 15e184a | 2010-01-11 00:05:43 -0800 | [diff] [blame] | 1196 | bool skip_empty = true; |
Dmitry Torokhov | 969b21c | 2006-04-02 00:09:34 -0500 | [diff] [blame] | 1197 | |
Dmitry Torokhov | 15e184a | 2010-01-11 00:05:43 -0800 | [diff] [blame] | 1198 | for (i = BITS_TO_LONGS(max) - 1; i >= 0; i--) { |
| 1199 | len += input_bits_to_string(buf + len, max(buf_size - len, 0), |
| 1200 | bitmap[i], skip_empty); |
| 1201 | if (len) { |
| 1202 | skip_empty = false; |
| 1203 | if (i > 0) |
| 1204 | len += snprintf(buf + len, max(buf_size - len, 0), " "); |
| 1205 | } |
| 1206 | } |
Dmitry Torokhov | 969b21c | 2006-04-02 00:09:34 -0500 | [diff] [blame] | 1207 | |
Dmitry Torokhov | 15e184a | 2010-01-11 00:05:43 -0800 | [diff] [blame] | 1208 | /* |
| 1209 | * If no output was produced print a single 0. |
| 1210 | */ |
| 1211 | if (len == 0) |
| 1212 | len = snprintf(buf, buf_size, "%d", 0); |
Dmitry Torokhov | 969b21c | 2006-04-02 00:09:34 -0500 | [diff] [blame] | 1213 | |
| 1214 | if (add_cr) |
| 1215 | len += snprintf(buf + len, max(buf_size - len, 0), "\n"); |
| 1216 | |
| 1217 | return len; |
| 1218 | } |
| 1219 | |
Dmitry Torokhov | 9657d75 | 2007-06-14 23:32:24 -0400 | [diff] [blame] | 1220 | #define INPUT_DEV_CAP_ATTR(ev, bm) \ |
| 1221 | static ssize_t input_dev_show_cap_##bm(struct device *dev, \ |
| 1222 | struct device_attribute *attr, \ |
| 1223 | char *buf) \ |
| 1224 | { \ |
| 1225 | struct input_dev *input_dev = to_input_dev(dev); \ |
| 1226 | int len = input_print_bitmap(buf, PAGE_SIZE, \ |
Dmitry Torokhov | 15e184a | 2010-01-11 00:05:43 -0800 | [diff] [blame] | 1227 | input_dev->bm##bit, ev##_MAX, \ |
| 1228 | true); \ |
Dmitry Torokhov | 9657d75 | 2007-06-14 23:32:24 -0400 | [diff] [blame] | 1229 | return min_t(int, len, PAGE_SIZE); \ |
| 1230 | } \ |
| 1231 | static DEVICE_ATTR(bm, S_IRUGO, input_dev_show_cap_##bm, NULL) |
Dmitry Torokhov | 5c1e9a6 | 2005-09-15 02:01:55 -0500 | [diff] [blame] | 1232 | |
| 1233 | INPUT_DEV_CAP_ATTR(EV, ev); |
| 1234 | INPUT_DEV_CAP_ATTR(KEY, key); |
| 1235 | INPUT_DEV_CAP_ATTR(REL, rel); |
| 1236 | INPUT_DEV_CAP_ATTR(ABS, abs); |
| 1237 | INPUT_DEV_CAP_ATTR(MSC, msc); |
| 1238 | INPUT_DEV_CAP_ATTR(LED, led); |
| 1239 | INPUT_DEV_CAP_ATTR(SND, snd); |
| 1240 | INPUT_DEV_CAP_ATTR(FF, ff); |
| 1241 | INPUT_DEV_CAP_ATTR(SW, sw); |
| 1242 | |
| 1243 | static struct attribute *input_dev_caps_attrs[] = { |
Dmitry Torokhov | 9657d75 | 2007-06-14 23:32:24 -0400 | [diff] [blame] | 1244 | &dev_attr_ev.attr, |
| 1245 | &dev_attr_key.attr, |
| 1246 | &dev_attr_rel.attr, |
| 1247 | &dev_attr_abs.attr, |
| 1248 | &dev_attr_msc.attr, |
| 1249 | &dev_attr_led.attr, |
| 1250 | &dev_attr_snd.attr, |
| 1251 | &dev_attr_ff.attr, |
| 1252 | &dev_attr_sw.attr, |
Dmitry Torokhov | 5c1e9a6 | 2005-09-15 02:01:55 -0500 | [diff] [blame] | 1253 | NULL |
| 1254 | }; |
| 1255 | |
| 1256 | static struct attribute_group input_dev_caps_attr_group = { |
| 1257 | .name = "capabilities", |
| 1258 | .attrs = input_dev_caps_attrs, |
| 1259 | }; |
| 1260 | |
David Brownell | a4dbd67 | 2009-06-24 10:06:31 -0700 | [diff] [blame] | 1261 | static const struct attribute_group *input_dev_attr_groups[] = { |
Dmitry Torokhov | cb9def4 | 2007-03-07 23:20:26 -0500 | [diff] [blame] | 1262 | &input_dev_attr_group, |
| 1263 | &input_dev_id_attr_group, |
| 1264 | &input_dev_caps_attr_group, |
| 1265 | NULL |
| 1266 | }; |
| 1267 | |
Dmitry Torokhov | 9657d75 | 2007-06-14 23:32:24 -0400 | [diff] [blame] | 1268 | static void input_dev_release(struct device *device) |
Dmitry Torokhov | d19fbe8 | 2005-09-15 02:01:39 -0500 | [diff] [blame] | 1269 | { |
Dmitry Torokhov | 9657d75 | 2007-06-14 23:32:24 -0400 | [diff] [blame] | 1270 | struct input_dev *dev = to_input_dev(device); |
Dmitry Torokhov | d19fbe8 | 2005-09-15 02:01:39 -0500 | [diff] [blame] | 1271 | |
Anssi Hannula | 509ca1a | 2006-07-19 01:40:22 -0400 | [diff] [blame] | 1272 | input_ff_destroy(dev); |
Dmitry Torokhov | d19fbe8 | 2005-09-15 02:01:39 -0500 | [diff] [blame] | 1273 | kfree(dev); |
Anssi Hannula | 509ca1a | 2006-07-19 01:40:22 -0400 | [diff] [blame] | 1274 | |
Dmitry Torokhov | d19fbe8 | 2005-09-15 02:01:39 -0500 | [diff] [blame] | 1275 | module_put(THIS_MODULE); |
| 1276 | } |
| 1277 | |
Dmitry Torokhov | a7fadbe | 2005-09-15 02:01:57 -0500 | [diff] [blame] | 1278 | /* |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 1279 | * Input uevent interface - loading event handlers based on |
Dmitry Torokhov | a7fadbe | 2005-09-15 02:01:57 -0500 | [diff] [blame] | 1280 | * device bitfields. |
| 1281 | */ |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 1282 | static int input_add_uevent_bm_var(struct kobj_uevent_env *env, |
Dmitry Torokhov | ac648a6 | 2006-04-02 00:09:51 -0500 | [diff] [blame] | 1283 | const char *name, unsigned long *bitmap, int max) |
Dmitry Torokhov | a7fadbe | 2005-09-15 02:01:57 -0500 | [diff] [blame] | 1284 | { |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 1285 | int len; |
| 1286 | |
| 1287 | if (add_uevent_var(env, "%s=", name)) |
Dmitry Torokhov | a7fadbe | 2005-09-15 02:01:57 -0500 | [diff] [blame] | 1288 | return -ENOMEM; |
| 1289 | |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 1290 | len = input_print_bitmap(&env->buf[env->buflen - 1], |
| 1291 | sizeof(env->buf) - env->buflen, |
Dmitry Torokhov | 15e184a | 2010-01-11 00:05:43 -0800 | [diff] [blame] | 1292 | bitmap, max, false); |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 1293 | if (len >= (sizeof(env->buf) - env->buflen)) |
Dmitry Torokhov | a7fadbe | 2005-09-15 02:01:57 -0500 | [diff] [blame] | 1294 | return -ENOMEM; |
| 1295 | |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 1296 | env->buflen += len; |
Dmitry Torokhov | a7fadbe | 2005-09-15 02:01:57 -0500 | [diff] [blame] | 1297 | return 0; |
| 1298 | } |
| 1299 | |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 1300 | static int input_add_uevent_modalias_var(struct kobj_uevent_env *env, |
Dmitry Torokhov | ac648a6 | 2006-04-02 00:09:51 -0500 | [diff] [blame] | 1301 | struct input_dev *dev) |
| 1302 | { |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 1303 | int len; |
| 1304 | |
| 1305 | if (add_uevent_var(env, "MODALIAS=")) |
Dmitry Torokhov | ac648a6 | 2006-04-02 00:09:51 -0500 | [diff] [blame] | 1306 | return -ENOMEM; |
| 1307 | |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 1308 | len = input_print_modalias(&env->buf[env->buflen - 1], |
| 1309 | sizeof(env->buf) - env->buflen, |
| 1310 | dev, 0); |
| 1311 | if (len >= (sizeof(env->buf) - env->buflen)) |
Dmitry Torokhov | ac648a6 | 2006-04-02 00:09:51 -0500 | [diff] [blame] | 1312 | return -ENOMEM; |
| 1313 | |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 1314 | env->buflen += len; |
Dmitry Torokhov | ac648a6 | 2006-04-02 00:09:51 -0500 | [diff] [blame] | 1315 | return 0; |
| 1316 | } |
| 1317 | |
Dmitry Torokhov | a7fadbe | 2005-09-15 02:01:57 -0500 | [diff] [blame] | 1318 | #define INPUT_ADD_HOTPLUG_VAR(fmt, val...) \ |
| 1319 | do { \ |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 1320 | int err = add_uevent_var(env, fmt, val); \ |
Dmitry Torokhov | a7fadbe | 2005-09-15 02:01:57 -0500 | [diff] [blame] | 1321 | if (err) \ |
| 1322 | return err; \ |
| 1323 | } while (0) |
| 1324 | |
| 1325 | #define INPUT_ADD_HOTPLUG_BM_VAR(name, bm, max) \ |
| 1326 | do { \ |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 1327 | int err = input_add_uevent_bm_var(env, name, bm, max); \ |
Dmitry Torokhov | a7fadbe | 2005-09-15 02:01:57 -0500 | [diff] [blame] | 1328 | if (err) \ |
| 1329 | return err; \ |
| 1330 | } while (0) |
| 1331 | |
Dmitry Torokhov | ac648a6 | 2006-04-02 00:09:51 -0500 | [diff] [blame] | 1332 | #define INPUT_ADD_HOTPLUG_MODALIAS_VAR(dev) \ |
| 1333 | do { \ |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 1334 | int err = input_add_uevent_modalias_var(env, dev); \ |
Dmitry Torokhov | ac648a6 | 2006-04-02 00:09:51 -0500 | [diff] [blame] | 1335 | if (err) \ |
| 1336 | return err; \ |
| 1337 | } while (0) |
| 1338 | |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 1339 | static int input_dev_uevent(struct device *device, struct kobj_uevent_env *env) |
Dmitry Torokhov | a7fadbe | 2005-09-15 02:01:57 -0500 | [diff] [blame] | 1340 | { |
Dmitry Torokhov | 9657d75 | 2007-06-14 23:32:24 -0400 | [diff] [blame] | 1341 | struct input_dev *dev = to_input_dev(device); |
Dmitry Torokhov | a7fadbe | 2005-09-15 02:01:57 -0500 | [diff] [blame] | 1342 | |
| 1343 | INPUT_ADD_HOTPLUG_VAR("PRODUCT=%x/%x/%x/%x", |
| 1344 | dev->id.bustype, dev->id.vendor, |
| 1345 | dev->id.product, dev->id.version); |
| 1346 | if (dev->name) |
| 1347 | INPUT_ADD_HOTPLUG_VAR("NAME=\"%s\"", dev->name); |
| 1348 | if (dev->phys) |
| 1349 | INPUT_ADD_HOTPLUG_VAR("PHYS=\"%s\"", dev->phys); |
Dmitry Torokhov | 08de1f0 | 2005-11-08 21:34:29 -0800 | [diff] [blame] | 1350 | if (dev->uniq) |
Dmitry Torokhov | a7fadbe | 2005-09-15 02:01:57 -0500 | [diff] [blame] | 1351 | INPUT_ADD_HOTPLUG_VAR("UNIQ=\"%s\"", dev->uniq); |
| 1352 | |
| 1353 | INPUT_ADD_HOTPLUG_BM_VAR("EV=", dev->evbit, EV_MAX); |
| 1354 | if (test_bit(EV_KEY, dev->evbit)) |
| 1355 | INPUT_ADD_HOTPLUG_BM_VAR("KEY=", dev->keybit, KEY_MAX); |
| 1356 | if (test_bit(EV_REL, dev->evbit)) |
| 1357 | INPUT_ADD_HOTPLUG_BM_VAR("REL=", dev->relbit, REL_MAX); |
| 1358 | if (test_bit(EV_ABS, dev->evbit)) |
| 1359 | INPUT_ADD_HOTPLUG_BM_VAR("ABS=", dev->absbit, ABS_MAX); |
| 1360 | if (test_bit(EV_MSC, dev->evbit)) |
| 1361 | INPUT_ADD_HOTPLUG_BM_VAR("MSC=", dev->mscbit, MSC_MAX); |
| 1362 | if (test_bit(EV_LED, dev->evbit)) |
| 1363 | INPUT_ADD_HOTPLUG_BM_VAR("LED=", dev->ledbit, LED_MAX); |
| 1364 | if (test_bit(EV_SND, dev->evbit)) |
| 1365 | INPUT_ADD_HOTPLUG_BM_VAR("SND=", dev->sndbit, SND_MAX); |
| 1366 | if (test_bit(EV_FF, dev->evbit)) |
| 1367 | INPUT_ADD_HOTPLUG_BM_VAR("FF=", dev->ffbit, FF_MAX); |
| 1368 | if (test_bit(EV_SW, dev->evbit)) |
| 1369 | INPUT_ADD_HOTPLUG_BM_VAR("SW=", dev->swbit, SW_MAX); |
| 1370 | |
Dmitry Torokhov | ac648a6 | 2006-04-02 00:09:51 -0500 | [diff] [blame] | 1371 | INPUT_ADD_HOTPLUG_MODALIAS_VAR(dev); |
Dmitry Torokhov | a7fadbe | 2005-09-15 02:01:57 -0500 | [diff] [blame] | 1372 | |
| 1373 | return 0; |
| 1374 | } |
| 1375 | |
Dmitry Torokhov | 3cc9635 | 2009-11-12 23:19:05 -0800 | [diff] [blame] | 1376 | #define INPUT_DO_TOGGLE(dev, type, bits, on) \ |
| 1377 | do { \ |
| 1378 | int i; \ |
| 1379 | bool active; \ |
| 1380 | \ |
| 1381 | if (!test_bit(EV_##type, dev->evbit)) \ |
| 1382 | break; \ |
| 1383 | \ |
| 1384 | for (i = 0; i < type##_MAX; i++) { \ |
| 1385 | if (!test_bit(i, dev->bits##bit)) \ |
| 1386 | continue; \ |
| 1387 | \ |
| 1388 | active = test_bit(i, dev->bits); \ |
| 1389 | if (!active && !on) \ |
| 1390 | continue; \ |
| 1391 | \ |
| 1392 | dev->event(dev, EV_##type, i, on ? active : 0); \ |
| 1393 | } \ |
Dmitry Torokhov | ffd0db9 | 2009-09-16 01:06:43 -0700 | [diff] [blame] | 1394 | } while (0) |
| 1395 | |
Andrew Morton | 1c4115e | 2009-10-01 15:43:55 -0700 | [diff] [blame] | 1396 | #ifdef CONFIG_PM |
Dmitry Torokhov | ffd0db9 | 2009-09-16 01:06:43 -0700 | [diff] [blame] | 1397 | static void input_dev_reset(struct input_dev *dev, bool activate) |
| 1398 | { |
| 1399 | if (!dev->event) |
| 1400 | return; |
| 1401 | |
| 1402 | INPUT_DO_TOGGLE(dev, LED, led, activate); |
| 1403 | INPUT_DO_TOGGLE(dev, SND, snd, activate); |
| 1404 | |
| 1405 | if (activate && test_bit(EV_REP, dev->evbit)) { |
| 1406 | dev->event(dev, EV_REP, REP_PERIOD, dev->rep[REP_PERIOD]); |
| 1407 | dev->event(dev, EV_REP, REP_DELAY, dev->rep[REP_DELAY]); |
| 1408 | } |
| 1409 | } |
| 1410 | |
Dmitry Torokhov | ffd0db9 | 2009-09-16 01:06:43 -0700 | [diff] [blame] | 1411 | static int input_dev_suspend(struct device *dev) |
| 1412 | { |
| 1413 | struct input_dev *input_dev = to_input_dev(dev); |
| 1414 | |
| 1415 | mutex_lock(&input_dev->mutex); |
| 1416 | input_dev_reset(input_dev, false); |
| 1417 | mutex_unlock(&input_dev->mutex); |
| 1418 | |
| 1419 | return 0; |
| 1420 | } |
| 1421 | |
| 1422 | static int input_dev_resume(struct device *dev) |
| 1423 | { |
| 1424 | struct input_dev *input_dev = to_input_dev(dev); |
| 1425 | |
| 1426 | mutex_lock(&input_dev->mutex); |
| 1427 | input_dev_reset(input_dev, true); |
| 1428 | mutex_unlock(&input_dev->mutex); |
| 1429 | |
| 1430 | return 0; |
| 1431 | } |
| 1432 | |
| 1433 | static const struct dev_pm_ops input_dev_pm_ops = { |
| 1434 | .suspend = input_dev_suspend, |
| 1435 | .resume = input_dev_resume, |
| 1436 | .poweroff = input_dev_suspend, |
| 1437 | .restore = input_dev_resume, |
| 1438 | }; |
| 1439 | #endif /* CONFIG_PM */ |
| 1440 | |
Dmitry Torokhov | 9657d75 | 2007-06-14 23:32:24 -0400 | [diff] [blame] | 1441 | static struct device_type input_dev_type = { |
| 1442 | .groups = input_dev_attr_groups, |
| 1443 | .release = input_dev_release, |
| 1444 | .uevent = input_dev_uevent, |
Dmitry Torokhov | ffd0db9 | 2009-09-16 01:06:43 -0700 | [diff] [blame] | 1445 | #ifdef CONFIG_PM |
| 1446 | .pm = &input_dev_pm_ops, |
| 1447 | #endif |
Dmitry Torokhov | 9657d75 | 2007-06-14 23:32:24 -0400 | [diff] [blame] | 1448 | }; |
| 1449 | |
Kay Sievers | e454cea | 2009-09-18 23:01:12 +0200 | [diff] [blame] | 1450 | static char *input_devnode(struct device *dev, mode_t *mode) |
Kay Sievers | aa5ed63 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 1451 | { |
| 1452 | return kasprintf(GFP_KERNEL, "input/%s", dev_name(dev)); |
| 1453 | } |
| 1454 | |
Greg Kroah-Hartman | ea9f240 | 2005-10-27 22:25:43 -0700 | [diff] [blame] | 1455 | struct class input_class = { |
Dmitry Torokhov | 9657d75 | 2007-06-14 23:32:24 -0400 | [diff] [blame] | 1456 | .name = "input", |
Kay Sievers | e454cea | 2009-09-18 23:01:12 +0200 | [diff] [blame] | 1457 | .devnode = input_devnode, |
Dmitry Torokhov | d19fbe8 | 2005-09-15 02:01:39 -0500 | [diff] [blame] | 1458 | }; |
Dmitry Torokhov | ca56fe0 | 2006-06-26 01:49:21 -0400 | [diff] [blame] | 1459 | EXPORT_SYMBOL_GPL(input_class); |
Dmitry Torokhov | d19fbe8 | 2005-09-15 02:01:39 -0500 | [diff] [blame] | 1460 | |
Dmitry Torokhov | 1447190 | 2006-11-02 23:26:55 -0500 | [diff] [blame] | 1461 | /** |
| 1462 | * input_allocate_device - allocate memory for new input device |
| 1463 | * |
| 1464 | * Returns prepared struct input_dev or NULL. |
| 1465 | * |
| 1466 | * NOTE: Use input_free_device() to free devices that have not been |
| 1467 | * registered; input_unregister_device() should be used for already |
| 1468 | * registered devices. |
| 1469 | */ |
Dmitry Torokhov | d19fbe8 | 2005-09-15 02:01:39 -0500 | [diff] [blame] | 1470 | struct input_dev *input_allocate_device(void) |
| 1471 | { |
| 1472 | struct input_dev *dev; |
| 1473 | |
| 1474 | dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL); |
| 1475 | if (dev) { |
Dmitry Torokhov | 9657d75 | 2007-06-14 23:32:24 -0400 | [diff] [blame] | 1476 | dev->dev.type = &input_dev_type; |
| 1477 | dev->dev.class = &input_class; |
| 1478 | device_initialize(&dev->dev); |
Dmitry Torokhov | f60d2b1 | 2006-06-26 01:48:36 -0400 | [diff] [blame] | 1479 | mutex_init(&dev->mutex); |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 1480 | spin_lock_init(&dev->event_lock); |
Dmitry Torokhov | d19fbe8 | 2005-09-15 02:01:39 -0500 | [diff] [blame] | 1481 | INIT_LIST_HEAD(&dev->h_list); |
| 1482 | INIT_LIST_HEAD(&dev->node); |
Dmitry Torokhov | 655816e | 2006-09-14 01:32:14 -0400 | [diff] [blame] | 1483 | |
| 1484 | __module_get(THIS_MODULE); |
Dmitry Torokhov | d19fbe8 | 2005-09-15 02:01:39 -0500 | [diff] [blame] | 1485 | } |
| 1486 | |
| 1487 | return dev; |
| 1488 | } |
Dmitry Torokhov | ca56fe0 | 2006-06-26 01:49:21 -0400 | [diff] [blame] | 1489 | EXPORT_SYMBOL(input_allocate_device); |
Dmitry Torokhov | d19fbe8 | 2005-09-15 02:01:39 -0500 | [diff] [blame] | 1490 | |
Dmitry Torokhov | 1447190 | 2006-11-02 23:26:55 -0500 | [diff] [blame] | 1491 | /** |
| 1492 | * input_free_device - free memory occupied by input_dev structure |
| 1493 | * @dev: input device to free |
| 1494 | * |
| 1495 | * This function should only be used if input_register_device() |
| 1496 | * was not called yet or if it failed. Once device was registered |
| 1497 | * use input_unregister_device() and memory will be freed once last |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 1498 | * reference to the device is dropped. |
Dmitry Torokhov | 1447190 | 2006-11-02 23:26:55 -0500 | [diff] [blame] | 1499 | * |
| 1500 | * Device should be allocated by input_allocate_device(). |
| 1501 | * |
| 1502 | * NOTE: If there are references to the input device then memory |
| 1503 | * will not be freed until last reference is dropped. |
| 1504 | */ |
Dmitry Torokhov | f60d2b1 | 2006-06-26 01:48:36 -0400 | [diff] [blame] | 1505 | void input_free_device(struct input_dev *dev) |
| 1506 | { |
Dmitry Torokhov | 54f9e36 | 2007-03-16 00:57:25 -0400 | [diff] [blame] | 1507 | if (dev) |
Dmitry Torokhov | f60d2b1 | 2006-06-26 01:48:36 -0400 | [diff] [blame] | 1508 | input_put_device(dev); |
Dmitry Torokhov | f60d2b1 | 2006-06-26 01:48:36 -0400 | [diff] [blame] | 1509 | } |
Dmitry Torokhov | ca56fe0 | 2006-06-26 01:49:21 -0400 | [diff] [blame] | 1510 | EXPORT_SYMBOL(input_free_device); |
Dmitry Torokhov | f60d2b1 | 2006-06-26 01:48:36 -0400 | [diff] [blame] | 1511 | |
Dmitry Torokhov | 534565f | 2007-04-25 00:53:18 -0400 | [diff] [blame] | 1512 | /** |
| 1513 | * input_set_capability - mark device as capable of a certain event |
| 1514 | * @dev: device that is capable of emitting or accepting event |
| 1515 | * @type: type of the event (EV_KEY, EV_REL, etc...) |
| 1516 | * @code: event code |
| 1517 | * |
| 1518 | * In addition to setting up corresponding bit in appropriate capability |
| 1519 | * bitmap the function also adjusts dev->evbit. |
| 1520 | */ |
| 1521 | void input_set_capability(struct input_dev *dev, unsigned int type, unsigned int code) |
| 1522 | { |
| 1523 | switch (type) { |
| 1524 | case EV_KEY: |
| 1525 | __set_bit(code, dev->keybit); |
| 1526 | break; |
| 1527 | |
| 1528 | case EV_REL: |
| 1529 | __set_bit(code, dev->relbit); |
| 1530 | break; |
| 1531 | |
| 1532 | case EV_ABS: |
| 1533 | __set_bit(code, dev->absbit); |
| 1534 | break; |
| 1535 | |
| 1536 | case EV_MSC: |
| 1537 | __set_bit(code, dev->mscbit); |
| 1538 | break; |
| 1539 | |
| 1540 | case EV_SW: |
| 1541 | __set_bit(code, dev->swbit); |
| 1542 | break; |
| 1543 | |
| 1544 | case EV_LED: |
| 1545 | __set_bit(code, dev->ledbit); |
| 1546 | break; |
| 1547 | |
| 1548 | case EV_SND: |
| 1549 | __set_bit(code, dev->sndbit); |
| 1550 | break; |
| 1551 | |
| 1552 | case EV_FF: |
| 1553 | __set_bit(code, dev->ffbit); |
| 1554 | break; |
| 1555 | |
Dmitry Baryshkov | 22d1c39 | 2007-12-14 01:21:03 -0500 | [diff] [blame] | 1556 | case EV_PWR: |
| 1557 | /* do nothing */ |
| 1558 | break; |
| 1559 | |
Dmitry Torokhov | 534565f | 2007-04-25 00:53:18 -0400 | [diff] [blame] | 1560 | default: |
| 1561 | printk(KERN_ERR |
| 1562 | "input_set_capability: unknown type %u (code %u)\n", |
| 1563 | type, code); |
| 1564 | dump_stack(); |
| 1565 | return; |
| 1566 | } |
| 1567 | |
| 1568 | __set_bit(type, dev->evbit); |
| 1569 | } |
| 1570 | EXPORT_SYMBOL(input_set_capability); |
| 1571 | |
Dmitry Torokhov | 92a3a58 | 2010-01-05 17:56:01 -0800 | [diff] [blame] | 1572 | #define INPUT_CLEANSE_BITMASK(dev, type, bits) \ |
| 1573 | do { \ |
| 1574 | if (!test_bit(EV_##type, dev->evbit)) \ |
| 1575 | memset(dev->bits##bit, 0, \ |
| 1576 | sizeof(dev->bits##bit)); \ |
| 1577 | } while (0) |
| 1578 | |
| 1579 | static void input_cleanse_bitmasks(struct input_dev *dev) |
| 1580 | { |
| 1581 | INPUT_CLEANSE_BITMASK(dev, KEY, key); |
| 1582 | INPUT_CLEANSE_BITMASK(dev, REL, rel); |
| 1583 | INPUT_CLEANSE_BITMASK(dev, ABS, abs); |
| 1584 | INPUT_CLEANSE_BITMASK(dev, MSC, msc); |
| 1585 | INPUT_CLEANSE_BITMASK(dev, LED, led); |
| 1586 | INPUT_CLEANSE_BITMASK(dev, SND, snd); |
| 1587 | INPUT_CLEANSE_BITMASK(dev, FF, ff); |
| 1588 | INPUT_CLEANSE_BITMASK(dev, SW, sw); |
| 1589 | } |
| 1590 | |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 1591 | /** |
| 1592 | * input_register_device - register device with input core |
| 1593 | * @dev: device to be registered |
| 1594 | * |
| 1595 | * This function registers device with input core. The device must be |
| 1596 | * allocated with input_allocate_device() and all it's capabilities |
| 1597 | * set up before registering. |
| 1598 | * If function fails the device must be freed with input_free_device(). |
| 1599 | * Once device has been successfully registered it can be unregistered |
| 1600 | * with input_unregister_device(); input_free_device() should not be |
| 1601 | * called in this case. |
| 1602 | */ |
Dmitry Torokhov | 5f94548 | 2005-11-02 22:51:46 -0500 | [diff] [blame] | 1603 | int input_register_device(struct input_dev *dev) |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1604 | { |
Dmitry Torokhov | bd0ef23 | 2005-11-20 00:56:31 -0500 | [diff] [blame] | 1605 | static atomic_t input_no = ATOMIC_INIT(0); |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1606 | struct input_handler *handler; |
Dmitry Torokhov | bd0ef23 | 2005-11-20 00:56:31 -0500 | [diff] [blame] | 1607 | const char *path; |
| 1608 | int error; |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1609 | |
Dmitry Torokhov | 4f93df4 | 2010-01-05 17:56:00 -0800 | [diff] [blame] | 1610 | /* Every input device generates EV_SYN/SYN_REPORT events. */ |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 1611 | __set_bit(EV_SYN, dev->evbit); |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1612 | |
Dmitry Torokhov | 4f93df4 | 2010-01-05 17:56:00 -0800 | [diff] [blame] | 1613 | /* KEY_RESERVED is not supposed to be transmitted to userspace. */ |
| 1614 | __clear_bit(KEY_RESERVED, dev->keybit); |
| 1615 | |
Dmitry Torokhov | 92a3a58 | 2010-01-05 17:56:01 -0800 | [diff] [blame] | 1616 | /* Make sure that bitmasks not mentioned in dev->evbit are clean. */ |
| 1617 | input_cleanse_bitmasks(dev); |
| 1618 | |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1619 | /* |
| 1620 | * If delay and period are pre-set by the driver, then autorepeating |
| 1621 | * is handled by the driver itself and we don't do it in input.c. |
| 1622 | */ |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1623 | init_timer(&dev->timer); |
| 1624 | if (!dev->rep[REP_DELAY] && !dev->rep[REP_PERIOD]) { |
| 1625 | dev->timer.data = (long) dev; |
| 1626 | dev->timer.function = input_repeat_key; |
| 1627 | dev->rep[REP_DELAY] = 250; |
| 1628 | dev->rep[REP_PERIOD] = 33; |
| 1629 | } |
| 1630 | |
Marvin Raaijmakers | c8e4c77 | 2007-03-14 22:50:42 -0400 | [diff] [blame] | 1631 | if (!dev->getkeycode) |
| 1632 | dev->getkeycode = input_default_getkeycode; |
| 1633 | |
| 1634 | if (!dev->setkeycode) |
| 1635 | dev->setkeycode = input_default_setkeycode; |
| 1636 | |
Kay Sievers | a6c2490 | 2008-10-30 00:07:50 -0400 | [diff] [blame] | 1637 | dev_set_name(&dev->dev, "input%ld", |
| 1638 | (unsigned long) atomic_inc_return(&input_no) - 1); |
Dmitry Torokhov | bd0ef23 | 2005-11-20 00:56:31 -0500 | [diff] [blame] | 1639 | |
Dmitry Torokhov | 9657d75 | 2007-06-14 23:32:24 -0400 | [diff] [blame] | 1640 | error = device_add(&dev->dev); |
Dmitry Torokhov | bd0ef23 | 2005-11-20 00:56:31 -0500 | [diff] [blame] | 1641 | if (error) |
| 1642 | return error; |
| 1643 | |
Dmitry Torokhov | 9657d75 | 2007-06-14 23:32:24 -0400 | [diff] [blame] | 1644 | path = kobject_get_path(&dev->dev.kobj, GFP_KERNEL); |
Dmitry Torokhov | bd0ef23 | 2005-11-20 00:56:31 -0500 | [diff] [blame] | 1645 | printk(KERN_INFO "input: %s as %s\n", |
| 1646 | dev->name ? dev->name : "Unspecified device", path ? path : "N/A"); |
| 1647 | kfree(path); |
Greg Kroah-Hartman | 1020402 | 2005-10-27 22:25:43 -0700 | [diff] [blame] | 1648 | |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 1649 | error = mutex_lock_interruptible(&input_mutex); |
| 1650 | if (error) { |
| 1651 | device_del(&dev->dev); |
| 1652 | return error; |
| 1653 | } |
| 1654 | |
| 1655 | list_add_tail(&dev->node, &input_dev_list); |
| 1656 | |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1657 | list_for_each_entry(handler, &input_handler_list, node) |
Dmitry Torokhov | 5b2a082 | 2007-04-12 01:29:46 -0400 | [diff] [blame] | 1658 | input_attach_handler(dev, handler); |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1659 | |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1660 | input_wakeup_procfs_readers(); |
Dmitry Torokhov | 5f94548 | 2005-11-02 22:51:46 -0500 | [diff] [blame] | 1661 | |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 1662 | mutex_unlock(&input_mutex); |
| 1663 | |
Dmitry Torokhov | 5f94548 | 2005-11-02 22:51:46 -0500 | [diff] [blame] | 1664 | return 0; |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1665 | } |
Dmitry Torokhov | ca56fe0 | 2006-06-26 01:49:21 -0400 | [diff] [blame] | 1666 | EXPORT_SYMBOL(input_register_device); |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1667 | |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 1668 | /** |
| 1669 | * input_unregister_device - unregister previously registered device |
| 1670 | * @dev: device to be unregistered |
| 1671 | * |
| 1672 | * This function unregisters an input device. Once device is unregistered |
| 1673 | * the caller should not try to access it as it may get freed at any moment. |
| 1674 | */ |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1675 | void input_unregister_device(struct input_dev *dev) |
| 1676 | { |
Dmitry Torokhov | 5b2a082 | 2007-04-12 01:29:46 -0400 | [diff] [blame] | 1677 | struct input_handle *handle, *next; |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1678 | |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 1679 | input_disconnect_device(dev); |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1680 | |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 1681 | mutex_lock(&input_mutex); |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1682 | |
Dmitry Torokhov | 5b2a082 | 2007-04-12 01:29:46 -0400 | [diff] [blame] | 1683 | list_for_each_entry_safe(handle, next, &dev->h_list, d_node) |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1684 | handle->handler->disconnect(handle); |
Dmitry Torokhov | 5b2a082 | 2007-04-12 01:29:46 -0400 | [diff] [blame] | 1685 | WARN_ON(!list_empty(&dev->h_list)); |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1686 | |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 1687 | del_timer_sync(&dev->timer); |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1688 | list_del_init(&dev->node); |
| 1689 | |
| 1690 | input_wakeup_procfs_readers(); |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 1691 | |
| 1692 | mutex_unlock(&input_mutex); |
| 1693 | |
| 1694 | device_unregister(&dev->dev); |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1695 | } |
Dmitry Torokhov | ca56fe0 | 2006-06-26 01:49:21 -0400 | [diff] [blame] | 1696 | EXPORT_SYMBOL(input_unregister_device); |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1697 | |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 1698 | /** |
| 1699 | * input_register_handler - register a new input handler |
| 1700 | * @handler: handler to be registered |
| 1701 | * |
| 1702 | * This function registers a new input handler (interface) for input |
| 1703 | * devices in the system and attaches it to all input devices that |
| 1704 | * are compatible with the handler. |
| 1705 | */ |
Dmitry Torokhov | 4263cf0 | 2006-09-14 01:32:39 -0400 | [diff] [blame] | 1706 | int input_register_handler(struct input_handler *handler) |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1707 | { |
| 1708 | struct input_dev *dev; |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 1709 | int retval; |
| 1710 | |
| 1711 | retval = mutex_lock_interruptible(&input_mutex); |
| 1712 | if (retval) |
| 1713 | return retval; |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1714 | |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1715 | INIT_LIST_HEAD(&handler->h_list); |
| 1716 | |
Dmitry Torokhov | 4263cf0 | 2006-09-14 01:32:39 -0400 | [diff] [blame] | 1717 | if (handler->fops != NULL) { |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 1718 | if (input_table[handler->minor >> 5]) { |
| 1719 | retval = -EBUSY; |
| 1720 | goto out; |
| 1721 | } |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1722 | input_table[handler->minor >> 5] = handler; |
Dmitry Torokhov | 4263cf0 | 2006-09-14 01:32:39 -0400 | [diff] [blame] | 1723 | } |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1724 | |
| 1725 | list_add_tail(&handler->node, &input_handler_list); |
| 1726 | |
| 1727 | list_for_each_entry(dev, &input_dev_list, node) |
Dmitry Torokhov | 5b2a082 | 2007-04-12 01:29:46 -0400 | [diff] [blame] | 1728 | input_attach_handler(dev, handler); |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1729 | |
| 1730 | input_wakeup_procfs_readers(); |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 1731 | |
| 1732 | out: |
| 1733 | mutex_unlock(&input_mutex); |
| 1734 | return retval; |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1735 | } |
Dmitry Torokhov | ca56fe0 | 2006-06-26 01:49:21 -0400 | [diff] [blame] | 1736 | EXPORT_SYMBOL(input_register_handler); |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1737 | |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 1738 | /** |
| 1739 | * input_unregister_handler - unregisters an input handler |
| 1740 | * @handler: handler to be unregistered |
| 1741 | * |
| 1742 | * This function disconnects a handler from its input devices and |
| 1743 | * removes it from lists of known handlers. |
| 1744 | */ |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1745 | void input_unregister_handler(struct input_handler *handler) |
| 1746 | { |
Dmitry Torokhov | 5b2a082 | 2007-04-12 01:29:46 -0400 | [diff] [blame] | 1747 | struct input_handle *handle, *next; |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1748 | |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 1749 | mutex_lock(&input_mutex); |
| 1750 | |
Dmitry Torokhov | 5b2a082 | 2007-04-12 01:29:46 -0400 | [diff] [blame] | 1751 | list_for_each_entry_safe(handle, next, &handler->h_list, h_node) |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1752 | handler->disconnect(handle); |
Dmitry Torokhov | 5b2a082 | 2007-04-12 01:29:46 -0400 | [diff] [blame] | 1753 | WARN_ON(!list_empty(&handler->h_list)); |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1754 | |
| 1755 | list_del_init(&handler->node); |
| 1756 | |
| 1757 | if (handler->fops != NULL) |
| 1758 | input_table[handler->minor >> 5] = NULL; |
| 1759 | |
| 1760 | input_wakeup_procfs_readers(); |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 1761 | |
| 1762 | mutex_unlock(&input_mutex); |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1763 | } |
Dmitry Torokhov | ca56fe0 | 2006-06-26 01:49:21 -0400 | [diff] [blame] | 1764 | EXPORT_SYMBOL(input_unregister_handler); |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1765 | |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 1766 | /** |
Dmitry Torokhov | 66d2a59 | 2009-12-01 21:54:35 -0800 | [diff] [blame] | 1767 | * input_handler_for_each_handle - handle iterator |
| 1768 | * @handler: input handler to iterate |
| 1769 | * @data: data for the callback |
| 1770 | * @fn: function to be called for each handle |
| 1771 | * |
| 1772 | * Iterate over @bus's list of devices, and call @fn for each, passing |
| 1773 | * it @data and stop when @fn returns a non-zero value. The function is |
| 1774 | * using RCU to traverse the list and therefore may be usind in atonic |
| 1775 | * contexts. The @fn callback is invoked from RCU critical section and |
| 1776 | * thus must not sleep. |
| 1777 | */ |
| 1778 | int input_handler_for_each_handle(struct input_handler *handler, void *data, |
| 1779 | int (*fn)(struct input_handle *, void *)) |
| 1780 | { |
| 1781 | struct input_handle *handle; |
| 1782 | int retval = 0; |
| 1783 | |
| 1784 | rcu_read_lock(); |
| 1785 | |
| 1786 | list_for_each_entry_rcu(handle, &handler->h_list, h_node) { |
| 1787 | retval = fn(handle, data); |
| 1788 | if (retval) |
| 1789 | break; |
| 1790 | } |
| 1791 | |
| 1792 | rcu_read_unlock(); |
| 1793 | |
| 1794 | return retval; |
| 1795 | } |
| 1796 | EXPORT_SYMBOL(input_handler_for_each_handle); |
| 1797 | |
| 1798 | /** |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 1799 | * input_register_handle - register a new input handle |
| 1800 | * @handle: handle to register |
| 1801 | * |
| 1802 | * This function puts a new input handle onto device's |
| 1803 | * and handler's lists so that events can flow through |
| 1804 | * it once it is opened using input_open_device(). |
| 1805 | * |
| 1806 | * This function is supposed to be called from handler's |
| 1807 | * connect() method. |
| 1808 | */ |
Dmitry Torokhov | 5b2a082 | 2007-04-12 01:29:46 -0400 | [diff] [blame] | 1809 | int input_register_handle(struct input_handle *handle) |
| 1810 | { |
| 1811 | struct input_handler *handler = handle->handler; |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 1812 | struct input_dev *dev = handle->dev; |
| 1813 | int error; |
Dmitry Torokhov | 5b2a082 | 2007-04-12 01:29:46 -0400 | [diff] [blame] | 1814 | |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 1815 | /* |
| 1816 | * We take dev->mutex here to prevent race with |
| 1817 | * input_release_device(). |
| 1818 | */ |
| 1819 | error = mutex_lock_interruptible(&dev->mutex); |
| 1820 | if (error) |
| 1821 | return error; |
Dmitry Torokhov | ef7995f | 2010-01-29 23:59:12 -0800 | [diff] [blame] | 1822 | |
| 1823 | /* |
| 1824 | * Filters go to the head of the list, normal handlers |
| 1825 | * to the tail. |
| 1826 | */ |
| 1827 | if (handler->filter) |
| 1828 | list_add_rcu(&handle->d_node, &dev->h_list); |
| 1829 | else |
| 1830 | list_add_tail_rcu(&handle->d_node, &dev->h_list); |
| 1831 | |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 1832 | mutex_unlock(&dev->mutex); |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 1833 | |
| 1834 | /* |
| 1835 | * Since we are supposed to be called from ->connect() |
| 1836 | * which is mutually exclusive with ->disconnect() |
| 1837 | * we can't be racing with input_unregister_handle() |
| 1838 | * and so separate lock is not needed here. |
| 1839 | */ |
Dmitry Torokhov | 66d2a59 | 2009-12-01 21:54:35 -0800 | [diff] [blame] | 1840 | list_add_tail_rcu(&handle->h_node, &handler->h_list); |
Dmitry Torokhov | 5b2a082 | 2007-04-12 01:29:46 -0400 | [diff] [blame] | 1841 | |
| 1842 | if (handler->start) |
| 1843 | handler->start(handle); |
| 1844 | |
| 1845 | return 0; |
| 1846 | } |
| 1847 | EXPORT_SYMBOL(input_register_handle); |
| 1848 | |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 1849 | /** |
| 1850 | * input_unregister_handle - unregister an input handle |
| 1851 | * @handle: handle to unregister |
| 1852 | * |
| 1853 | * This function removes input handle from device's |
| 1854 | * and handler's lists. |
| 1855 | * |
| 1856 | * This function is supposed to be called from handler's |
| 1857 | * disconnect() method. |
| 1858 | */ |
Dmitry Torokhov | 5b2a082 | 2007-04-12 01:29:46 -0400 | [diff] [blame] | 1859 | void input_unregister_handle(struct input_handle *handle) |
| 1860 | { |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 1861 | struct input_dev *dev = handle->dev; |
| 1862 | |
Dmitry Torokhov | 66d2a59 | 2009-12-01 21:54:35 -0800 | [diff] [blame] | 1863 | list_del_rcu(&handle->h_node); |
Dmitry Torokhov | 8006479 | 2007-08-30 00:22:11 -0400 | [diff] [blame] | 1864 | |
| 1865 | /* |
| 1866 | * Take dev->mutex to prevent race with input_release_device(). |
| 1867 | */ |
| 1868 | mutex_lock(&dev->mutex); |
| 1869 | list_del_rcu(&handle->d_node); |
| 1870 | mutex_unlock(&dev->mutex); |
Dmitry Torokhov | 66d2a59 | 2009-12-01 21:54:35 -0800 | [diff] [blame] | 1871 | |
Dmitry Torokhov | 82ba56c | 2007-10-13 15:46:55 -0400 | [diff] [blame] | 1872 | synchronize_rcu(); |
Dmitry Torokhov | 5b2a082 | 2007-04-12 01:29:46 -0400 | [diff] [blame] | 1873 | } |
| 1874 | EXPORT_SYMBOL(input_unregister_handle); |
| 1875 | |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1876 | static int input_open_file(struct inode *inode, struct file *file) |
| 1877 | { |
Jonathan Corbet | 2edbf85 | 2008-05-15 10:37:16 -0600 | [diff] [blame] | 1878 | struct input_handler *handler; |
Arjan van de Ven | 99ac48f | 2006-03-28 01:56:41 -0800 | [diff] [blame] | 1879 | const struct file_operations *old_fops, *new_fops = NULL; |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1880 | int err; |
| 1881 | |
Arnd Bergmann | 2f2177c | 2010-03-09 20:38:48 -0800 | [diff] [blame] | 1882 | err = mutex_lock_interruptible(&input_mutex); |
| 1883 | if (err) |
| 1884 | return err; |
| 1885 | |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1886 | /* No load-on-demand here? */ |
Jonathan Corbet | 2edbf85 | 2008-05-15 10:37:16 -0600 | [diff] [blame] | 1887 | handler = input_table[iminor(inode) >> 5]; |
Arnd Bergmann | 2f2177c | 2010-03-09 20:38:48 -0800 | [diff] [blame] | 1888 | if (handler) |
| 1889 | new_fops = fops_get(handler->fops); |
| 1890 | |
| 1891 | mutex_unlock(&input_mutex); |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1892 | |
| 1893 | /* |
| 1894 | * That's _really_ odd. Usually NULL ->open means "nothing special", |
| 1895 | * not "no device". Oh, well... |
| 1896 | */ |
Arnd Bergmann | 2f2177c | 2010-03-09 20:38:48 -0800 | [diff] [blame] | 1897 | if (!new_fops || !new_fops->open) { |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1898 | fops_put(new_fops); |
Jonathan Corbet | 2edbf85 | 2008-05-15 10:37:16 -0600 | [diff] [blame] | 1899 | err = -ENODEV; |
| 1900 | goto out; |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1901 | } |
Arnd Bergmann | 2f2177c | 2010-03-09 20:38:48 -0800 | [diff] [blame] | 1902 | |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1903 | old_fops = file->f_op; |
| 1904 | file->f_op = new_fops; |
| 1905 | |
| 1906 | err = new_fops->open(inode, file); |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1907 | if (err) { |
| 1908 | fops_put(file->f_op); |
| 1909 | file->f_op = fops_get(old_fops); |
| 1910 | } |
| 1911 | fops_put(old_fops); |
Jonathan Corbet | 2edbf85 | 2008-05-15 10:37:16 -0600 | [diff] [blame] | 1912 | out: |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1913 | return err; |
| 1914 | } |
| 1915 | |
Arjan van de Ven | 2b8693c | 2007-02-12 00:55:32 -0800 | [diff] [blame] | 1916 | static const struct file_operations input_fops = { |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1917 | .owner = THIS_MODULE, |
| 1918 | .open = input_open_file, |
| 1919 | }; |
| 1920 | |
Henrik Rydberg | 61994a6 | 2009-04-28 07:45:31 -0700 | [diff] [blame] | 1921 | static void __init input_init_abs_bypass(void) |
| 1922 | { |
| 1923 | const unsigned int *p; |
| 1924 | |
| 1925 | for (p = input_abs_bypass_init_data; *p; p++) |
| 1926 | input_abs_bypass[BIT_WORD(*p)] |= BIT_MASK(*p); |
| 1927 | } |
| 1928 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | static int __init input_init(void) |
| 1930 | { |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1931 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1932 | |
Henrik Rydberg | 61994a6 | 2009-04-28 07:45:31 -0700 | [diff] [blame] | 1933 | input_init_abs_bypass(); |
| 1934 | |
Greg Kroah-Hartman | ea9f240 | 2005-10-27 22:25:43 -0700 | [diff] [blame] | 1935 | err = class_register(&input_class); |
Dmitry Torokhov | d19fbe8 | 2005-09-15 02:01:39 -0500 | [diff] [blame] | 1936 | if (err) { |
| 1937 | printk(KERN_ERR "input: unable to register input_dev class\n"); |
| 1938 | return err; |
| 1939 | } |
| 1940 | |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1941 | err = input_proc_init(); |
| 1942 | if (err) |
Greg Kroah-Hartman | b0fdfeb | 2005-10-27 22:25:43 -0700 | [diff] [blame] | 1943 | goto fail1; |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1944 | |
| 1945 | err = register_chrdev(INPUT_MAJOR, "input", &input_fops); |
| 1946 | if (err) { |
| 1947 | printk(KERN_ERR "input: unable to register char major %d", INPUT_MAJOR); |
Greg Kroah-Hartman | b0fdfeb | 2005-10-27 22:25:43 -0700 | [diff] [blame] | 1948 | goto fail2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1949 | } |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1950 | |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1951 | return 0; |
| 1952 | |
Greg Kroah-Hartman | b0fdfeb | 2005-10-27 22:25:43 -0700 | [diff] [blame] | 1953 | fail2: input_proc_exit(); |
Greg Kroah-Hartman | ea9f240 | 2005-10-27 22:25:43 -0700 | [diff] [blame] | 1954 | fail1: class_unregister(&input_class); |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1955 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1956 | } |
| 1957 | |
| 1958 | static void __exit input_exit(void) |
| 1959 | { |
Dmitry Torokhov | f96b434 | 2005-06-30 00:50:29 -0500 | [diff] [blame] | 1960 | input_proc_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1961 | unregister_chrdev(INPUT_MAJOR, "input"); |
Greg Kroah-Hartman | ea9f240 | 2005-10-27 22:25:43 -0700 | [diff] [blame] | 1962 | class_unregister(&input_class); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1963 | } |
| 1964 | |
| 1965 | subsys_initcall(input_init); |
| 1966 | module_exit(input_exit); |