aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/input.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/input/input.c')
-rw-r--r--drivers/input/input.c220
1 files changed, 163 insertions, 57 deletions
diff --git a/drivers/input/input.c b/drivers/input/input.c
index 9c79bd56b51a..a9b025f4147a 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -33,25 +33,6 @@ MODULE_LICENSE("GPL");
33 33
34#define INPUT_DEVICES 256 34#define INPUT_DEVICES 256
35 35
36/*
37 * EV_ABS events which should not be cached are listed here.
38 */
39static unsigned int input_abs_bypass_init_data[] __initdata = {
40 ABS_MT_TOUCH_MAJOR,
41 ABS_MT_TOUCH_MINOR,
42 ABS_MT_WIDTH_MAJOR,
43 ABS_MT_WIDTH_MINOR,
44 ABS_MT_ORIENTATION,
45 ABS_MT_POSITION_X,
46 ABS_MT_POSITION_Y,
47 ABS_MT_TOOL_TYPE,
48 ABS_MT_BLOB_ID,
49 ABS_MT_TRACKING_ID,
50 ABS_MT_PRESSURE,
51 0
52};
53static unsigned long input_abs_bypass[BITS_TO_LONGS(ABS_CNT)];
54
55static LIST_HEAD(input_dev_list); 36static LIST_HEAD(input_dev_list);
56static LIST_HEAD(input_handler_list); 37static LIST_HEAD(input_handler_list);
57 38
@@ -181,6 +162,56 @@ static void input_stop_autorepeat(struct input_dev *dev)
181#define INPUT_PASS_TO_DEVICE 2 162#define INPUT_PASS_TO_DEVICE 2
182#define INPUT_PASS_TO_ALL (INPUT_PASS_TO_HANDLERS | INPUT_PASS_TO_DEVICE) 163#define INPUT_PASS_TO_ALL (INPUT_PASS_TO_HANDLERS | INPUT_PASS_TO_DEVICE)
183 164
165static int input_handle_abs_event(struct input_dev *dev,
166 unsigned int code, int *pval)
167{
168 bool is_mt_event;
169 int *pold;
170
171 if (code == ABS_MT_SLOT) {
172 /*
173 * "Stage" the event; we'll flush it later, when we
174 * get actiual touch data.
175 */
176 if (*pval >= 0 && *pval < dev->mtsize)
177 dev->slot = *pval;
178
179 return INPUT_IGNORE_EVENT;
180 }
181
182 is_mt_event = code >= ABS_MT_FIRST && code <= ABS_MT_LAST;
183
184 if (!is_mt_event) {
185 pold = &dev->absinfo[code].value;
186 } else if (dev->mt) {
187 struct input_mt_slot *mtslot = &dev->mt[dev->slot];
188 pold = &mtslot->abs[code - ABS_MT_FIRST];
189 } else {
190 /*
191 * Bypass filtering for multitouch events when
192 * not employing slots.
193 */
194 pold = NULL;
195 }
196
197 if (pold) {
198 *pval = input_defuzz_abs_event(*pval, *pold,
199 dev->absinfo[code].fuzz);
200 if (*pold == *pval)
201 return INPUT_IGNORE_EVENT;
202
203 *pold = *pval;
204 }
205
206 /* Flush pending "slot" event */
207 if (is_mt_event && dev->slot != input_abs_get_val(dev, ABS_MT_SLOT)) {
208 input_abs_set_val(dev, ABS_MT_SLOT, dev->slot);
209 input_pass_event(dev, EV_ABS, ABS_MT_SLOT, dev->slot);
210 }
211
212 return INPUT_PASS_TO_HANDLERS;
213}
214
184static void input_handle_event(struct input_dev *dev, 215static void input_handle_event(struct input_dev *dev,
185 unsigned int type, unsigned int code, int value) 216 unsigned int type, unsigned int code, int value)
186{ 217{
@@ -196,12 +227,12 @@ static void input_handle_event(struct input_dev *dev,
196 227
197 case SYN_REPORT: 228 case SYN_REPORT:
198 if (!dev->sync) { 229 if (!dev->sync) {
199 dev->sync = 1; 230 dev->sync = true;
200 disposition = INPUT_PASS_TO_HANDLERS; 231 disposition = INPUT_PASS_TO_HANDLERS;
201 } 232 }
202 break; 233 break;
203 case SYN_MT_REPORT: 234 case SYN_MT_REPORT:
204 dev->sync = 0; 235 dev->sync = false;
205 disposition = INPUT_PASS_TO_HANDLERS; 236 disposition = INPUT_PASS_TO_HANDLERS;
206 break; 237 break;
207 } 238 }
@@ -233,21 +264,9 @@ static void input_handle_event(struct input_dev *dev,
233 break; 264 break;
234 265
235 case EV_ABS: 266 case EV_ABS:
236 if (is_event_supported(code, dev->absbit, ABS_MAX)) { 267 if (is_event_supported(code, dev->absbit, ABS_MAX))
237 268 disposition = input_handle_abs_event(dev, code, &value);
238 if (test_bit(code, input_abs_bypass)) {
239 disposition = INPUT_PASS_TO_HANDLERS;
240 break;
241 }
242 269
243 value = input_defuzz_abs_event(value,
244 dev->abs[code], dev->absfuzz[code]);
245
246 if (dev->abs[code] != value) {
247 dev->abs[code] = value;
248 disposition = INPUT_PASS_TO_HANDLERS;
249 }
250 }
251 break; 270 break;
252 271
253 case EV_REL: 272 case EV_REL:
@@ -298,7 +317,7 @@ static void input_handle_event(struct input_dev *dev,
298 } 317 }
299 318
300 if (disposition != INPUT_IGNORE_EVENT && type != EV_SYN) 319 if (disposition != INPUT_IGNORE_EVENT && type != EV_SYN)
301 dev->sync = 0; 320 dev->sync = false;
302 321
303 if ((disposition & INPUT_PASS_TO_DEVICE) && dev->event) 322 if ((disposition & INPUT_PASS_TO_DEVICE) && dev->event)
304 dev->event(dev, type, code, value); 323 dev->event(dev, type, code, value);
@@ -372,6 +391,43 @@ void input_inject_event(struct input_handle *handle,
372EXPORT_SYMBOL(input_inject_event); 391EXPORT_SYMBOL(input_inject_event);
373 392
374/** 393/**
394 * input_alloc_absinfo - allocates array of input_absinfo structs
395 * @dev: the input device emitting absolute events
396 *
397 * If the absinfo struct the caller asked for is already allocated, this
398 * functions will not do anything.
399 */
400void input_alloc_absinfo(struct input_dev *dev)
401{
402 if (!dev->absinfo)
403 dev->absinfo = kcalloc(ABS_CNT, sizeof(struct input_absinfo),
404 GFP_KERNEL);
405
406 WARN(!dev->absinfo, "%s(): kcalloc() failed?\n", __func__);
407}
408EXPORT_SYMBOL(input_alloc_absinfo);
409
410void input_set_abs_params(struct input_dev *dev, unsigned int axis,
411 int min, int max, int fuzz, int flat)
412{
413 struct input_absinfo *absinfo;
414
415 input_alloc_absinfo(dev);
416 if (!dev->absinfo)
417 return;
418
419 absinfo = &dev->absinfo[axis];
420 absinfo->minimum = min;
421 absinfo->maximum = max;
422 absinfo->fuzz = fuzz;
423 absinfo->flat = flat;
424
425 dev->absbit[BIT_WORD(axis)] |= BIT_MASK(axis);
426}
427EXPORT_SYMBOL(input_set_abs_params);
428
429
430/**
375 * input_grab_device - grabs device for exclusive use 431 * input_grab_device - grabs device for exclusive use
376 * @handle: input handle that wants to own the device 432 * @handle: input handle that wants to own the device
377 * 433 *
@@ -528,12 +584,30 @@ void input_close_device(struct input_handle *handle)
528EXPORT_SYMBOL(input_close_device); 584EXPORT_SYMBOL(input_close_device);
529 585
530/* 586/*
587 * Simulate keyup events for all keys that are marked as pressed.
588 * The function must be called with dev->event_lock held.
589 */
590static void input_dev_release_keys(struct input_dev *dev)
591{
592 int code;
593
594 if (is_event_supported(EV_KEY, dev->evbit, EV_MAX)) {
595 for (code = 0; code <= KEY_MAX; code++) {
596 if (is_event_supported(code, dev->keybit, KEY_MAX) &&
597 __test_and_clear_bit(code, dev->key)) {
598 input_pass_event(dev, EV_KEY, code, 0);
599 }
600 }
601 input_pass_event(dev, EV_SYN, SYN_REPORT, 1);
602 }
603}
604
605/*
531 * Prepare device for unregistering 606 * Prepare device for unregistering
532 */ 607 */
533static void input_disconnect_device(struct input_dev *dev) 608static void input_disconnect_device(struct input_dev *dev)
534{ 609{
535 struct input_handle *handle; 610 struct input_handle *handle;
536 int code;
537 611
538 /* 612 /*
539 * Mark device as going away. Note that we take dev->mutex here 613 * Mark device as going away. Note that we take dev->mutex here
@@ -552,15 +626,7 @@ static void input_disconnect_device(struct input_dev *dev)
552 * generate events even after we done here but they will not 626 * generate events even after we done here but they will not
553 * reach any handlers. 627 * reach any handlers.
554 */ 628 */
555 if (is_event_supported(EV_KEY, dev->evbit, EV_MAX)) { 629 input_dev_release_keys(dev);
556 for (code = 0; code <= KEY_MAX; code++) {
557 if (is_event_supported(code, dev->keybit, KEY_MAX) &&
558 __test_and_clear_bit(code, dev->key)) {
559 input_pass_event(dev, EV_KEY, code, 0);
560 }
561 }
562 input_pass_event(dev, EV_SYN, SYN_REPORT, 1);
563 }
564 630
565 list_for_each_entry(handle, &dev->h_list, d_node) 631 list_for_each_entry(handle, &dev->h_list, d_node)
566 handle->open = 0; 632 handle->open = 0;
@@ -684,7 +750,7 @@ int input_set_keycode(struct input_dev *dev,
684 unsigned int scancode, unsigned int keycode) 750 unsigned int scancode, unsigned int keycode)
685{ 751{
686 unsigned long flags; 752 unsigned long flags;
687 int old_keycode; 753 unsigned int old_keycode;
688 int retval; 754 int retval;
689 755
690 if (keycode > KEY_MAX) 756 if (keycode > KEY_MAX)
@@ -1278,6 +1344,8 @@ static void input_dev_release(struct device *device)
1278 struct input_dev *dev = to_input_dev(device); 1344 struct input_dev *dev = to_input_dev(device);
1279 1345
1280 input_ff_destroy(dev); 1346 input_ff_destroy(dev);
1347 input_mt_destroy_slots(dev);
1348 kfree(dev->absinfo);
1281 kfree(dev); 1349 kfree(dev);
1282 1350
1283 module_put(THIS_MODULE); 1351 module_put(THIS_MODULE);
@@ -1433,6 +1501,15 @@ static int input_dev_resume(struct device *dev)
1433 1501
1434 mutex_lock(&input_dev->mutex); 1502 mutex_lock(&input_dev->mutex);
1435 input_dev_reset(input_dev, true); 1503 input_dev_reset(input_dev, true);
1504
1505 /*
1506 * Keys that have been pressed at suspend time are unlikely
1507 * to be still pressed when we resume.
1508 */
1509 spin_lock_irq(&input_dev->event_lock);
1510 input_dev_release_keys(input_dev);
1511 spin_unlock_irq(&input_dev->event_lock);
1512
1436 mutex_unlock(&input_dev->mutex); 1513 mutex_unlock(&input_dev->mutex);
1437 1514
1438 return 0; 1515 return 0;
@@ -1518,6 +1595,45 @@ void input_free_device(struct input_dev *dev)
1518EXPORT_SYMBOL(input_free_device); 1595EXPORT_SYMBOL(input_free_device);
1519 1596
1520/** 1597/**
1598 * input_mt_create_slots() - create MT input slots
1599 * @dev: input device supporting MT events and finger tracking
1600 * @num_slots: number of slots used by the device
1601 *
1602 * This function allocates all necessary memory for MT slot handling
1603 * in the input device, and adds ABS_MT_SLOT to the device capabilities.
1604 */
1605int input_mt_create_slots(struct input_dev *dev, unsigned int num_slots)
1606{
1607 if (!num_slots)
1608 return 0;
1609
1610 dev->mt = kcalloc(num_slots, sizeof(struct input_mt_slot), GFP_KERNEL);
1611 if (!dev->mt)
1612 return -ENOMEM;
1613
1614 dev->mtsize = num_slots;
1615 input_set_abs_params(dev, ABS_MT_SLOT, 0, num_slots - 1, 0, 0);
1616
1617 return 0;
1618}
1619EXPORT_SYMBOL(input_mt_create_slots);
1620
1621/**
1622 * input_mt_destroy_slots() - frees the MT slots of the input device
1623 * @dev: input device with allocated MT slots
1624 *
1625 * This function is only needed in error path as the input core will
1626 * automatically free the MT slots when the device is destroyed.
1627 */
1628void input_mt_destroy_slots(struct input_dev *dev)
1629{
1630 kfree(dev->mt);
1631 dev->mt = NULL;
1632 dev->mtsize = 0;
1633}
1634EXPORT_SYMBOL(input_mt_destroy_slots);
1635
1636/**
1521 * input_set_capability - mark device as capable of a certain event 1637 * input_set_capability - mark device as capable of a certain event
1522 * @dev: device that is capable of emitting or accepting event 1638 * @dev: device that is capable of emitting or accepting event
1523 * @type: type of the event (EV_KEY, EV_REL, etc...) 1639 * @type: type of the event (EV_KEY, EV_REL, etc...)
@@ -1926,20 +2042,10 @@ static const struct file_operations input_fops = {
1926 .open = input_open_file, 2042 .open = input_open_file,
1927}; 2043};
1928 2044
1929static void __init input_init_abs_bypass(void)
1930{
1931 const unsigned int *p;
1932
1933 for (p = input_abs_bypass_init_data; *p; p++)
1934 input_abs_bypass[BIT_WORD(*p)] |= BIT_MASK(*p);
1935}
1936
1937static int __init input_init(void) 2045static int __init input_init(void)
1938{ 2046{
1939 int err; 2047 int err;
1940 2048
1941 input_init_abs_bypass();
1942
1943 err = class_register(&input_class); 2049 err = class_register(&input_class);
1944 if (err) { 2050 if (err) {
1945 printk(KERN_ERR "input: unable to register input_dev class\n"); 2051 printk(KERN_ERR "input: unable to register input_dev class\n");