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.c182
1 files changed, 125 insertions, 57 deletions
diff --git a/drivers/input/input.c b/drivers/input/input.c
index 9c79bd56b51a..e1243b4b32a5 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->abs[code];
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->absfuzz[code]);
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 != dev->abs[ABS_MT_SLOT]) {
208 dev->abs[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);
@@ -528,12 +547,30 @@ void input_close_device(struct input_handle *handle)
528EXPORT_SYMBOL(input_close_device); 547EXPORT_SYMBOL(input_close_device);
529 548
530/* 549/*
550 * Simulate keyup events for all keys that are marked as pressed.
551 * The function must be called with dev->event_lock held.
552 */
553static void input_dev_release_keys(struct input_dev *dev)
554{
555 int code;
556
557 if (is_event_supported(EV_KEY, dev->evbit, EV_MAX)) {
558 for (code = 0; code <= KEY_MAX; code++) {
559 if (is_event_supported(code, dev->keybit, KEY_MAX) &&
560 __test_and_clear_bit(code, dev->key)) {
561 input_pass_event(dev, EV_KEY, code, 0);
562 }
563 }
564 input_pass_event(dev, EV_SYN, SYN_REPORT, 1);
565 }
566}
567
568/*
531 * Prepare device for unregistering 569 * Prepare device for unregistering
532 */ 570 */
533static void input_disconnect_device(struct input_dev *dev) 571static void input_disconnect_device(struct input_dev *dev)
534{ 572{
535 struct input_handle *handle; 573 struct input_handle *handle;
536 int code;
537 574
538 /* 575 /*
539 * Mark device as going away. Note that we take dev->mutex here 576 * Mark device as going away. Note that we take dev->mutex here
@@ -552,15 +589,7 @@ static void input_disconnect_device(struct input_dev *dev)
552 * generate events even after we done here but they will not 589 * generate events even after we done here but they will not
553 * reach any handlers. 590 * reach any handlers.
554 */ 591 */
555 if (is_event_supported(EV_KEY, dev->evbit, EV_MAX)) { 592 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 593
565 list_for_each_entry(handle, &dev->h_list, d_node) 594 list_for_each_entry(handle, &dev->h_list, d_node)
566 handle->open = 0; 595 handle->open = 0;
@@ -684,7 +713,7 @@ int input_set_keycode(struct input_dev *dev,
684 unsigned int scancode, unsigned int keycode) 713 unsigned int scancode, unsigned int keycode)
685{ 714{
686 unsigned long flags; 715 unsigned long flags;
687 int old_keycode; 716 unsigned int old_keycode;
688 int retval; 717 int retval;
689 718
690 if (keycode > KEY_MAX) 719 if (keycode > KEY_MAX)
@@ -1278,6 +1307,7 @@ static void input_dev_release(struct device *device)
1278 struct input_dev *dev = to_input_dev(device); 1307 struct input_dev *dev = to_input_dev(device);
1279 1308
1280 input_ff_destroy(dev); 1309 input_ff_destroy(dev);
1310 input_mt_destroy_slots(dev);
1281 kfree(dev); 1311 kfree(dev);
1282 1312
1283 module_put(THIS_MODULE); 1313 module_put(THIS_MODULE);
@@ -1433,6 +1463,15 @@ static int input_dev_resume(struct device *dev)
1433 1463
1434 mutex_lock(&input_dev->mutex); 1464 mutex_lock(&input_dev->mutex);
1435 input_dev_reset(input_dev, true); 1465 input_dev_reset(input_dev, true);
1466
1467 /*
1468 * Keys that have been pressed at suspend time are unlikely
1469 * to be still pressed when we resume.
1470 */
1471 spin_lock_irq(&input_dev->event_lock);
1472 input_dev_release_keys(input_dev);
1473 spin_unlock_irq(&input_dev->event_lock);
1474
1436 mutex_unlock(&input_dev->mutex); 1475 mutex_unlock(&input_dev->mutex);
1437 1476
1438 return 0; 1477 return 0;
@@ -1518,6 +1557,45 @@ void input_free_device(struct input_dev *dev)
1518EXPORT_SYMBOL(input_free_device); 1557EXPORT_SYMBOL(input_free_device);
1519 1558
1520/** 1559/**
1560 * input_mt_create_slots() - create MT input slots
1561 * @dev: input device supporting MT events and finger tracking
1562 * @num_slots: number of slots used by the device
1563 *
1564 * This function allocates all necessary memory for MT slot handling
1565 * in the input device, and adds ABS_MT_SLOT to the device capabilities.
1566 */
1567int input_mt_create_slots(struct input_dev *dev, unsigned int num_slots)
1568{
1569 if (!num_slots)
1570 return 0;
1571
1572 dev->mt = kcalloc(num_slots, sizeof(struct input_mt_slot), GFP_KERNEL);
1573 if (!dev->mt)
1574 return -ENOMEM;
1575
1576 dev->mtsize = num_slots;
1577 input_set_abs_params(dev, ABS_MT_SLOT, 0, num_slots - 1, 0, 0);
1578
1579 return 0;
1580}
1581EXPORT_SYMBOL(input_mt_create_slots);
1582
1583/**
1584 * input_mt_destroy_slots() - frees the MT slots of the input device
1585 * @dev: input device with allocated MT slots
1586 *
1587 * This function is only needed in error path as the input core will
1588 * automatically free the MT slots when the device is destroyed.
1589 */
1590void input_mt_destroy_slots(struct input_dev *dev)
1591{
1592 kfree(dev->mt);
1593 dev->mt = NULL;
1594 dev->mtsize = 0;
1595}
1596EXPORT_SYMBOL(input_mt_destroy_slots);
1597
1598/**
1521 * input_set_capability - mark device as capable of a certain event 1599 * input_set_capability - mark device as capable of a certain event
1522 * @dev: device that is capable of emitting or accepting event 1600 * @dev: device that is capable of emitting or accepting event
1523 * @type: type of the event (EV_KEY, EV_REL, etc...) 1601 * @type: type of the event (EV_KEY, EV_REL, etc...)
@@ -1926,20 +2004,10 @@ static const struct file_operations input_fops = {
1926 .open = input_open_file, 2004 .open = input_open_file,
1927}; 2005};
1928 2006
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) 2007static int __init input_init(void)
1938{ 2008{
1939 int err; 2009 int err;
1940 2010
1941 input_init_abs_bypass();
1942
1943 err = class_register(&input_class); 2011 err = class_register(&input_class);
1944 if (err) { 2012 if (err) {
1945 printk(KERN_ERR "input: unable to register input_dev class\n"); 2013 printk(KERN_ERR "input: unable to register input_dev class\n");