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.c90
1 files changed, 62 insertions, 28 deletions
diff --git a/drivers/input/input.c b/drivers/input/input.c
index d092ef9291da..db409d6bd5d2 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -24,7 +24,6 @@
24#include <linux/device.h> 24#include <linux/device.h>
25#include <linux/mutex.h> 25#include <linux/mutex.h>
26#include <linux/rcupdate.h> 26#include <linux/rcupdate.h>
27#include <linux/smp_lock.h>
28#include "input-compat.h" 27#include "input-compat.h"
29 28
30MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>"); 29MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>");
@@ -74,6 +73,7 @@ static int input_defuzz_abs_event(int value, int old_val, int fuzz)
74 * dev->event_lock held and interrupts disabled. 73 * dev->event_lock held and interrupts disabled.
75 */ 74 */
76static void input_pass_event(struct input_dev *dev, 75static void input_pass_event(struct input_dev *dev,
76 struct input_handler *src_handler,
77 unsigned int type, unsigned int code, int value) 77 unsigned int type, unsigned int code, int value)
78{ 78{
79 struct input_handler *handler; 79 struct input_handler *handler;
@@ -92,6 +92,15 @@ static void input_pass_event(struct input_dev *dev,
92 continue; 92 continue;
93 93
94 handler = handle->handler; 94 handler = handle->handler;
95
96 /*
97 * If this is the handler that injected this
98 * particular event we want to skip it to avoid
99 * filters firing again and again.
100 */
101 if (handler == src_handler)
102 continue;
103
95 if (!handler->filter) { 104 if (!handler->filter) {
96 if (filtered) 105 if (filtered)
97 break; 106 break;
@@ -121,7 +130,7 @@ static void input_repeat_key(unsigned long data)
121 if (test_bit(dev->repeat_key, dev->key) && 130 if (test_bit(dev->repeat_key, dev->key) &&
122 is_event_supported(dev->repeat_key, dev->keybit, KEY_MAX)) { 131 is_event_supported(dev->repeat_key, dev->keybit, KEY_MAX)) {
123 132
124 input_pass_event(dev, EV_KEY, dev->repeat_key, 2); 133 input_pass_event(dev, NULL, EV_KEY, dev->repeat_key, 2);
125 134
126 if (dev->sync) { 135 if (dev->sync) {
127 /* 136 /*
@@ -130,7 +139,7 @@ static void input_repeat_key(unsigned long data)
130 * Otherwise assume that the driver will send 139 * Otherwise assume that the driver will send
131 * SYN_REPORT once it's done. 140 * SYN_REPORT once it's done.
132 */ 141 */
133 input_pass_event(dev, EV_SYN, SYN_REPORT, 1); 142 input_pass_event(dev, NULL, EV_SYN, SYN_REPORT, 1);
134 } 143 }
135 144
136 if (dev->rep[REP_PERIOD]) 145 if (dev->rep[REP_PERIOD])
@@ -163,6 +172,7 @@ static void input_stop_autorepeat(struct input_dev *dev)
163#define INPUT_PASS_TO_ALL (INPUT_PASS_TO_HANDLERS | INPUT_PASS_TO_DEVICE) 172#define INPUT_PASS_TO_ALL (INPUT_PASS_TO_HANDLERS | INPUT_PASS_TO_DEVICE)
164 173
165static int input_handle_abs_event(struct input_dev *dev, 174static int input_handle_abs_event(struct input_dev *dev,
175 struct input_handler *src_handler,
166 unsigned int code, int *pval) 176 unsigned int code, int *pval)
167{ 177{
168 bool is_mt_event; 178 bool is_mt_event;
@@ -206,13 +216,15 @@ static int input_handle_abs_event(struct input_dev *dev,
206 /* Flush pending "slot" event */ 216 /* Flush pending "slot" event */
207 if (is_mt_event && dev->slot != input_abs_get_val(dev, ABS_MT_SLOT)) { 217 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); 218 input_abs_set_val(dev, ABS_MT_SLOT, dev->slot);
209 input_pass_event(dev, EV_ABS, ABS_MT_SLOT, dev->slot); 219 input_pass_event(dev, src_handler,
220 EV_ABS, ABS_MT_SLOT, dev->slot);
210 } 221 }
211 222
212 return INPUT_PASS_TO_HANDLERS; 223 return INPUT_PASS_TO_HANDLERS;
213} 224}
214 225
215static void input_handle_event(struct input_dev *dev, 226static void input_handle_event(struct input_dev *dev,
227 struct input_handler *src_handler,
216 unsigned int type, unsigned int code, int value) 228 unsigned int type, unsigned int code, int value)
217{ 229{
218 int disposition = INPUT_IGNORE_EVENT; 230 int disposition = INPUT_IGNORE_EVENT;
@@ -265,7 +277,8 @@ static void input_handle_event(struct input_dev *dev,
265 277
266 case EV_ABS: 278 case EV_ABS:
267 if (is_event_supported(code, dev->absbit, ABS_MAX)) 279 if (is_event_supported(code, dev->absbit, ABS_MAX))
268 disposition = input_handle_abs_event(dev, code, &value); 280 disposition = input_handle_abs_event(dev, src_handler,
281 code, &value);
269 282
270 break; 283 break;
271 284
@@ -323,7 +336,7 @@ static void input_handle_event(struct input_dev *dev,
323 dev->event(dev, type, code, value); 336 dev->event(dev, type, code, value);
324 337
325 if (disposition & INPUT_PASS_TO_HANDLERS) 338 if (disposition & INPUT_PASS_TO_HANDLERS)
326 input_pass_event(dev, type, code, value); 339 input_pass_event(dev, src_handler, type, code, value);
327} 340}
328 341
329/** 342/**
@@ -352,7 +365,7 @@ void input_event(struct input_dev *dev,
352 365
353 spin_lock_irqsave(&dev->event_lock, flags); 366 spin_lock_irqsave(&dev->event_lock, flags);
354 add_input_randomness(type, code, value); 367 add_input_randomness(type, code, value);
355 input_handle_event(dev, type, code, value); 368 input_handle_event(dev, NULL, type, code, value);
356 spin_unlock_irqrestore(&dev->event_lock, flags); 369 spin_unlock_irqrestore(&dev->event_lock, flags);
357 } 370 }
358} 371}
@@ -382,7 +395,8 @@ void input_inject_event(struct input_handle *handle,
382 rcu_read_lock(); 395 rcu_read_lock();
383 grab = rcu_dereference(dev->grab); 396 grab = rcu_dereference(dev->grab);
384 if (!grab || grab == handle) 397 if (!grab || grab == handle)
385 input_handle_event(dev, type, code, value); 398 input_handle_event(dev, handle->handler,
399 type, code, value);
386 rcu_read_unlock(); 400 rcu_read_unlock();
387 401
388 spin_unlock_irqrestore(&dev->event_lock, flags); 402 spin_unlock_irqrestore(&dev->event_lock, flags);
@@ -595,10 +609,10 @@ static void input_dev_release_keys(struct input_dev *dev)
595 for (code = 0; code <= KEY_MAX; code++) { 609 for (code = 0; code <= KEY_MAX; code++) {
596 if (is_event_supported(code, dev->keybit, KEY_MAX) && 610 if (is_event_supported(code, dev->keybit, KEY_MAX) &&
597 __test_and_clear_bit(code, dev->key)) { 611 __test_and_clear_bit(code, dev->key)) {
598 input_pass_event(dev, EV_KEY, code, 0); 612 input_pass_event(dev, NULL, EV_KEY, code, 0);
599 } 613 }
600 } 614 }
601 input_pass_event(dev, EV_SYN, SYN_REPORT, 1); 615 input_pass_event(dev, NULL, EV_SYN, SYN_REPORT, 1);
602 } 616 }
603} 617}
604 618
@@ -738,7 +752,7 @@ static int input_default_setkeycode(struct input_dev *dev,
738 if (index >= dev->keycodemax) 752 if (index >= dev->keycodemax)
739 return -EINVAL; 753 return -EINVAL;
740 754
741 if (dev->keycodesize < sizeof(dev->keycode) && 755 if (dev->keycodesize < sizeof(ke->keycode) &&
742 (ke->keycode >> (dev->keycodesize * 8))) 756 (ke->keycode >> (dev->keycodesize * 8)))
743 return -EINVAL; 757 return -EINVAL;
744 758
@@ -873,9 +887,9 @@ int input_set_keycode(struct input_dev *dev,
873 !is_event_supported(old_keycode, dev->keybit, KEY_MAX) && 887 !is_event_supported(old_keycode, dev->keybit, KEY_MAX) &&
874 __test_and_clear_bit(old_keycode, dev->key)) { 888 __test_and_clear_bit(old_keycode, dev->key)) {
875 889
876 input_pass_event(dev, EV_KEY, old_keycode, 0); 890 input_pass_event(dev, NULL, EV_KEY, old_keycode, 0);
877 if (dev->sync) 891 if (dev->sync)
878 input_pass_event(dev, EV_SYN, SYN_REPORT, 1); 892 input_pass_event(dev, NULL, EV_SYN, SYN_REPORT, 1);
879 } 893 }
880 894
881 out: 895 out:
@@ -1565,8 +1579,7 @@ static int input_dev_uevent(struct device *device, struct kobj_uevent_env *env)
1565 } \ 1579 } \
1566 } while (0) 1580 } while (0)
1567 1581
1568#ifdef CONFIG_PM 1582static void input_dev_toggle(struct input_dev *dev, bool activate)
1569static void input_dev_reset(struct input_dev *dev, bool activate)
1570{ 1583{
1571 if (!dev->event) 1584 if (!dev->event)
1572 return; 1585 return;
@@ -1580,12 +1593,44 @@ static void input_dev_reset(struct input_dev *dev, bool activate)
1580 } 1593 }
1581} 1594}
1582 1595
1596/**
1597 * input_reset_device() - reset/restore the state of input device
1598 * @dev: input device whose state needs to be reset
1599 *
1600 * This function tries to reset the state of an opened input device and
1601 * bring internal state and state if the hardware in sync with each other.
1602 * We mark all keys as released, restore LED state, repeat rate, etc.
1603 */
1604void input_reset_device(struct input_dev *dev)
1605{
1606 mutex_lock(&dev->mutex);
1607
1608 if (dev->users) {
1609 input_dev_toggle(dev, true);
1610
1611 /*
1612 * Keys that have been pressed at suspend time are unlikely
1613 * to be still pressed when we resume.
1614 */
1615 spin_lock_irq(&dev->event_lock);
1616 input_dev_release_keys(dev);
1617 spin_unlock_irq(&dev->event_lock);
1618 }
1619
1620 mutex_unlock(&dev->mutex);
1621}
1622EXPORT_SYMBOL(input_reset_device);
1623
1624#ifdef CONFIG_PM
1583static int input_dev_suspend(struct device *dev) 1625static int input_dev_suspend(struct device *dev)
1584{ 1626{
1585 struct input_dev *input_dev = to_input_dev(dev); 1627 struct input_dev *input_dev = to_input_dev(dev);
1586 1628
1587 mutex_lock(&input_dev->mutex); 1629 mutex_lock(&input_dev->mutex);
1588 input_dev_reset(input_dev, false); 1630
1631 if (input_dev->users)
1632 input_dev_toggle(input_dev, false);
1633
1589 mutex_unlock(&input_dev->mutex); 1634 mutex_unlock(&input_dev->mutex);
1590 1635
1591 return 0; 1636 return 0;
@@ -1595,18 +1640,7 @@ static int input_dev_resume(struct device *dev)
1595{ 1640{
1596 struct input_dev *input_dev = to_input_dev(dev); 1641 struct input_dev *input_dev = to_input_dev(dev);
1597 1642
1598 mutex_lock(&input_dev->mutex); 1643 input_reset_device(input_dev);
1599 input_dev_reset(input_dev, true);
1600
1601 /*
1602 * Keys that have been pressed at suspend time are unlikely
1603 * to be still pressed when we resume.
1604 */
1605 spin_lock_irq(&input_dev->event_lock);
1606 input_dev_release_keys(input_dev);
1607 spin_unlock_irq(&input_dev->event_lock);
1608
1609 mutex_unlock(&input_dev->mutex);
1610 1644
1611 return 0; 1645 return 0;
1612} 1646}