aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/input.c
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2012-10-01 17:40:51 -0400
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2012-10-01 17:40:51 -0400
commit7774036808011ceecc88cef01dfafcce39ed9fc5 (patch)
treee88670cf3fba9d885b3d71c00fb9a7809ed3f9e2 /drivers/input/input.c
parentfb4f552e895cec29934d94a99cbd1f1f00448a88 (diff)
parent51c80b74002f86477d691ed7c8ac479dcfa6271c (diff)
Merge branch 'for-next' of git://github.com/rydberg/linux into next
Merge Henrik's updates to multitouch code. Even though Jiri already pulled them in I need to do it too since my changes to evdev using dynamic major would clash with them.
Diffstat (limited to 'drivers/input/input.c')
-rw-r--r--drivers/input/input.c254
1 files changed, 169 insertions, 85 deletions
diff --git a/drivers/input/input.c b/drivers/input/input.c
index 768e46b05ef0..ace3f7c4226d 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -47,6 +47,8 @@ static DEFINE_MUTEX(input_mutex);
47 47
48static struct input_handler *input_table[8]; 48static struct input_handler *input_table[8];
49 49
50static const struct input_value input_value_sync = { EV_SYN, SYN_REPORT, 1 };
51
50static inline int is_event_supported(unsigned int code, 52static inline int is_event_supported(unsigned int code,
51 unsigned long *bm, unsigned int max) 53 unsigned long *bm, unsigned int max)
52{ 54{
@@ -69,42 +71,102 @@ static int input_defuzz_abs_event(int value, int old_val, int fuzz)
69 return value; 71 return value;
70} 72}
71 73
74static void input_start_autorepeat(struct input_dev *dev, int code)
75{
76 if (test_bit(EV_REP, dev->evbit) &&
77 dev->rep[REP_PERIOD] && dev->rep[REP_DELAY] &&
78 dev->timer.data) {
79 dev->repeat_key = code;
80 mod_timer(&dev->timer,
81 jiffies + msecs_to_jiffies(dev->rep[REP_DELAY]));
82 }
83}
84
85static void input_stop_autorepeat(struct input_dev *dev)
86{
87 del_timer(&dev->timer);
88}
89
72/* 90/*
73 * Pass event first through all filters and then, if event has not been 91 * Pass event first through all filters and then, if event has not been
74 * filtered out, through all open handles. This function is called with 92 * filtered out, through all open handles. This function is called with
75 * dev->event_lock held and interrupts disabled. 93 * dev->event_lock held and interrupts disabled.
76 */ 94 */
77static void input_pass_event(struct input_dev *dev, 95static unsigned int input_to_handler(struct input_handle *handle,
78 unsigned int type, unsigned int code, int value) 96 struct input_value *vals, unsigned int count)
97{
98 struct input_handler *handler = handle->handler;
99 struct input_value *end = vals;
100 struct input_value *v;
101
102 for (v = vals; v != vals + count; v++) {
103 if (handler->filter &&
104 handler->filter(handle, v->type, v->code, v->value))
105 continue;
106 if (end != v)
107 *end = *v;
108 end++;
109 }
110
111 count = end - vals;
112 if (!count)
113 return 0;
114
115 if (handler->events)
116 handler->events(handle, vals, count);
117 else if (handler->event)
118 for (v = vals; v != end; v++)
119 handler->event(handle, v->type, v->code, v->value);
120
121 return count;
122}
123
124/*
125 * Pass values first through all filters and then, if event has not been
126 * filtered out, through all open handles. This function is called with
127 * dev->event_lock held and interrupts disabled.
128 */
129static void input_pass_values(struct input_dev *dev,
130 struct input_value *vals, unsigned int count)
79{ 131{
80 struct input_handler *handler;
81 struct input_handle *handle; 132 struct input_handle *handle;
133 struct input_value *v;
134
135 if (!count)
136 return;
82 137
83 rcu_read_lock(); 138 rcu_read_lock();
84 139
85 handle = rcu_dereference(dev->grab); 140 handle = rcu_dereference(dev->grab);
86 if (handle) 141 if (handle) {
87 handle->handler->event(handle, type, code, value); 142 count = input_to_handler(handle, vals, count);
88 else { 143 } else {
89 bool filtered = false; 144 list_for_each_entry_rcu(handle, &dev->h_list, d_node)
90 145 if (handle->open)
91 list_for_each_entry_rcu(handle, &dev->h_list, d_node) { 146 count = input_to_handler(handle, vals, count);
92 if (!handle->open) 147 }
93 continue;
94 148
95 handler = handle->handler; 149 rcu_read_unlock();
96 if (!handler->filter) {
97 if (filtered)
98 break;
99 150
100 handler->event(handle, type, code, value); 151 add_input_randomness(vals->type, vals->code, vals->value);
101 152
102 } else if (handler->filter(handle, type, code, value)) 153 /* trigger auto repeat for key events */
103 filtered = true; 154 for (v = vals; v != vals + count; v++) {
155 if (v->type == EV_KEY && v->value != 2) {
156 if (v->value)
157 input_start_autorepeat(dev, v->code);
158 else
159 input_stop_autorepeat(dev);
104 } 160 }
105 } 161 }
162}
106 163
107 rcu_read_unlock(); 164static void input_pass_event(struct input_dev *dev,
165 unsigned int type, unsigned int code, int value)
166{
167 struct input_value vals[] = { { type, code, value } };
168
169 input_pass_values(dev, vals, ARRAY_SIZE(vals));
108} 170}
109 171
110/* 172/*
@@ -121,18 +183,12 @@ static void input_repeat_key(unsigned long data)
121 183
122 if (test_bit(dev->repeat_key, dev->key) && 184 if (test_bit(dev->repeat_key, dev->key) &&
123 is_event_supported(dev->repeat_key, dev->keybit, KEY_MAX)) { 185 is_event_supported(dev->repeat_key, dev->keybit, KEY_MAX)) {
186 struct input_value vals[] = {
187 { EV_KEY, dev->repeat_key, 2 },
188 input_value_sync
189 };
124 190
125 input_pass_event(dev, EV_KEY, dev->repeat_key, 2); 191 input_pass_values(dev, vals, ARRAY_SIZE(vals));
126
127 if (dev->sync) {
128 /*
129 * Only send SYN_REPORT if we are not in a middle
130 * of driver parsing a new hardware packet.
131 * Otherwise assume that the driver will send
132 * SYN_REPORT once it's done.
133 */
134 input_pass_event(dev, EV_SYN, SYN_REPORT, 1);
135 }
136 192
137 if (dev->rep[REP_PERIOD]) 193 if (dev->rep[REP_PERIOD])
138 mod_timer(&dev->timer, jiffies + 194 mod_timer(&dev->timer, jiffies +
@@ -142,30 +198,17 @@ static void input_repeat_key(unsigned long data)
142 spin_unlock_irqrestore(&dev->event_lock, flags); 198 spin_unlock_irqrestore(&dev->event_lock, flags);
143} 199}
144 200
145static void input_start_autorepeat(struct input_dev *dev, int code)
146{
147 if (test_bit(EV_REP, dev->evbit) &&
148 dev->rep[REP_PERIOD] && dev->rep[REP_DELAY] &&
149 dev->timer.data) {
150 dev->repeat_key = code;
151 mod_timer(&dev->timer,
152 jiffies + msecs_to_jiffies(dev->rep[REP_DELAY]));
153 }
154}
155
156static void input_stop_autorepeat(struct input_dev *dev)
157{
158 del_timer(&dev->timer);
159}
160
161#define INPUT_IGNORE_EVENT 0 201#define INPUT_IGNORE_EVENT 0
162#define INPUT_PASS_TO_HANDLERS 1 202#define INPUT_PASS_TO_HANDLERS 1
163#define INPUT_PASS_TO_DEVICE 2 203#define INPUT_PASS_TO_DEVICE 2
204#define INPUT_SLOT 4
205#define INPUT_FLUSH 8
164#define INPUT_PASS_TO_ALL (INPUT_PASS_TO_HANDLERS | INPUT_PASS_TO_DEVICE) 206#define INPUT_PASS_TO_ALL (INPUT_PASS_TO_HANDLERS | INPUT_PASS_TO_DEVICE)
165 207
166static int input_handle_abs_event(struct input_dev *dev, 208static int input_handle_abs_event(struct input_dev *dev,
167 unsigned int code, int *pval) 209 unsigned int code, int *pval)
168{ 210{
211 struct input_mt *mt = dev->mt;
169 bool is_mt_event; 212 bool is_mt_event;
170 int *pold; 213 int *pold;
171 214
@@ -174,8 +217,8 @@ static int input_handle_abs_event(struct input_dev *dev,
174 * "Stage" the event; we'll flush it later, when we 217 * "Stage" the event; we'll flush it later, when we
175 * get actual touch data. 218 * get actual touch data.
176 */ 219 */
177 if (*pval >= 0 && *pval < dev->mtsize) 220 if (mt && *pval >= 0 && *pval < mt->num_slots)
178 dev->slot = *pval; 221 mt->slot = *pval;
179 222
180 return INPUT_IGNORE_EVENT; 223 return INPUT_IGNORE_EVENT;
181 } 224 }
@@ -184,9 +227,8 @@ static int input_handle_abs_event(struct input_dev *dev,
184 227
185 if (!is_mt_event) { 228 if (!is_mt_event) {
186 pold = &dev->absinfo[code].value; 229 pold = &dev->absinfo[code].value;
187 } else if (dev->mt) { 230 } else if (mt) {
188 struct input_mt_slot *mtslot = &dev->mt[dev->slot]; 231 pold = &mt->slots[mt->slot].abs[code - ABS_MT_FIRST];
189 pold = &mtslot->abs[code - ABS_MT_FIRST];
190 } else { 232 } else {
191 /* 233 /*
192 * Bypass filtering for multi-touch events when 234 * Bypass filtering for multi-touch events when
@@ -205,16 +247,16 @@ static int input_handle_abs_event(struct input_dev *dev,
205 } 247 }
206 248
207 /* Flush pending "slot" event */ 249 /* Flush pending "slot" event */
208 if (is_mt_event && dev->slot != input_abs_get_val(dev, ABS_MT_SLOT)) { 250 if (is_mt_event && mt && mt->slot != input_abs_get_val(dev, ABS_MT_SLOT)) {
209 input_abs_set_val(dev, ABS_MT_SLOT, dev->slot); 251 input_abs_set_val(dev, ABS_MT_SLOT, mt->slot);
210 input_pass_event(dev, EV_ABS, ABS_MT_SLOT, dev->slot); 252 return INPUT_PASS_TO_HANDLERS | INPUT_SLOT;
211 } 253 }
212 254
213 return INPUT_PASS_TO_HANDLERS; 255 return INPUT_PASS_TO_HANDLERS;
214} 256}
215 257
216static void input_handle_event(struct input_dev *dev, 258static int input_get_disposition(struct input_dev *dev,
217 unsigned int type, unsigned int code, int value) 259 unsigned int type, unsigned int code, int value)
218{ 260{
219 int disposition = INPUT_IGNORE_EVENT; 261 int disposition = INPUT_IGNORE_EVENT;
220 262
@@ -227,37 +269,34 @@ static void input_handle_event(struct input_dev *dev,
227 break; 269 break;
228 270
229 case SYN_REPORT: 271 case SYN_REPORT:
230 if (!dev->sync) { 272 disposition = INPUT_PASS_TO_HANDLERS | INPUT_FLUSH;
231 dev->sync = true;
232 disposition = INPUT_PASS_TO_HANDLERS;
233 }
234 break; 273 break;
235 case SYN_MT_REPORT: 274 case SYN_MT_REPORT:
236 dev->sync = false;
237 disposition = INPUT_PASS_TO_HANDLERS; 275 disposition = INPUT_PASS_TO_HANDLERS;
238 break; 276 break;
239 } 277 }
240 break; 278 break;
241 279
242 case EV_KEY: 280 case EV_KEY:
243 if (is_event_supported(code, dev->keybit, KEY_MAX) && 281 if (is_event_supported(code, dev->keybit, KEY_MAX)) {
244 !!test_bit(code, dev->key) != value) {
245 282
246 if (value != 2) { 283 /* auto-repeat bypasses state updates */
247 __change_bit(code, dev->key); 284 if (value == 2) {
248 if (value) 285 disposition = INPUT_PASS_TO_HANDLERS;
249 input_start_autorepeat(dev, code); 286 break;
250 else
251 input_stop_autorepeat(dev);
252 } 287 }
253 288
254 disposition = INPUT_PASS_TO_HANDLERS; 289 if (!!test_bit(code, dev->key) != !!value) {
290
291 __change_bit(code, dev->key);
292 disposition = INPUT_PASS_TO_HANDLERS;
293 }
255 } 294 }
256 break; 295 break;
257 296
258 case EV_SW: 297 case EV_SW:
259 if (is_event_supported(code, dev->swbit, SW_MAX) && 298 if (is_event_supported(code, dev->swbit, SW_MAX) &&
260 !!test_bit(code, dev->sw) != value) { 299 !!test_bit(code, dev->sw) != !!value) {
261 300
262 __change_bit(code, dev->sw); 301 __change_bit(code, dev->sw);
263 disposition = INPUT_PASS_TO_HANDLERS; 302 disposition = INPUT_PASS_TO_HANDLERS;
@@ -284,7 +323,7 @@ static void input_handle_event(struct input_dev *dev,
284 323
285 case EV_LED: 324 case EV_LED:
286 if (is_event_supported(code, dev->ledbit, LED_MAX) && 325 if (is_event_supported(code, dev->ledbit, LED_MAX) &&
287 !!test_bit(code, dev->led) != value) { 326 !!test_bit(code, dev->led) != !!value) {
288 327
289 __change_bit(code, dev->led); 328 __change_bit(code, dev->led);
290 disposition = INPUT_PASS_TO_ALL; 329 disposition = INPUT_PASS_TO_ALL;
@@ -317,14 +356,48 @@ static void input_handle_event(struct input_dev *dev,
317 break; 356 break;
318 } 357 }
319 358
320 if (disposition != INPUT_IGNORE_EVENT && type != EV_SYN) 359 return disposition;
321 dev->sync = false; 360}
361
362static void input_handle_event(struct input_dev *dev,
363 unsigned int type, unsigned int code, int value)
364{
365 int disposition;
366
367 disposition = input_get_disposition(dev, type, code, value);
322 368
323 if ((disposition & INPUT_PASS_TO_DEVICE) && dev->event) 369 if ((disposition & INPUT_PASS_TO_DEVICE) && dev->event)
324 dev->event(dev, type, code, value); 370 dev->event(dev, type, code, value);
325 371
326 if (disposition & INPUT_PASS_TO_HANDLERS) 372 if (!dev->vals)
327 input_pass_event(dev, type, code, value); 373 return;
374
375 if (disposition & INPUT_PASS_TO_HANDLERS) {
376 struct input_value *v;
377
378 if (disposition & INPUT_SLOT) {
379 v = &dev->vals[dev->num_vals++];
380 v->type = EV_ABS;
381 v->code = ABS_MT_SLOT;
382 v->value = dev->mt->slot;
383 }
384
385 v = &dev->vals[dev->num_vals++];
386 v->type = type;
387 v->code = code;
388 v->value = value;
389 }
390
391 if (disposition & INPUT_FLUSH) {
392 if (dev->num_vals >= 2)
393 input_pass_values(dev, dev->vals, dev->num_vals);
394 dev->num_vals = 0;
395 } else if (dev->num_vals >= dev->max_vals - 2) {
396 dev->vals[dev->num_vals++] = input_value_sync;
397 input_pass_values(dev, dev->vals, dev->num_vals);
398 dev->num_vals = 0;
399 }
400
328} 401}
329 402
330/** 403/**
@@ -352,7 +425,6 @@ void input_event(struct input_dev *dev,
352 if (is_event_supported(type, dev->evbit, EV_MAX)) { 425 if (is_event_supported(type, dev->evbit, EV_MAX)) {
353 426
354 spin_lock_irqsave(&dev->event_lock, flags); 427 spin_lock_irqsave(&dev->event_lock, flags);
355 add_input_randomness(type, code, value);
356 input_handle_event(dev, type, code, value); 428 input_handle_event(dev, type, code, value);
357 spin_unlock_irqrestore(&dev->event_lock, flags); 429 spin_unlock_irqrestore(&dev->event_lock, flags);
358 } 430 }
@@ -831,10 +903,12 @@ int input_set_keycode(struct input_dev *dev,
831 if (test_bit(EV_KEY, dev->evbit) && 903 if (test_bit(EV_KEY, dev->evbit) &&
832 !is_event_supported(old_keycode, dev->keybit, KEY_MAX) && 904 !is_event_supported(old_keycode, dev->keybit, KEY_MAX) &&
833 __test_and_clear_bit(old_keycode, dev->key)) { 905 __test_and_clear_bit(old_keycode, dev->key)) {
906 struct input_value vals[] = {
907 { EV_KEY, old_keycode, 0 },
908 input_value_sync
909 };
834 910
835 input_pass_event(dev, EV_KEY, old_keycode, 0); 911 input_pass_values(dev, vals, ARRAY_SIZE(vals));
836 if (dev->sync)
837 input_pass_event(dev, EV_SYN, SYN_REPORT, 1);
838 } 912 }
839 913
840 out: 914 out:
@@ -1425,6 +1499,7 @@ static void input_dev_release(struct device *device)
1425 input_ff_destroy(dev); 1499 input_ff_destroy(dev);
1426 input_mt_destroy_slots(dev); 1500 input_mt_destroy_slots(dev);
1427 kfree(dev->absinfo); 1501 kfree(dev->absinfo);
1502 kfree(dev->vals);
1428 kfree(dev); 1503 kfree(dev);
1429 1504
1430 module_put(THIS_MODULE); 1505 module_put(THIS_MODULE);
@@ -1760,8 +1835,8 @@ static unsigned int input_estimate_events_per_packet(struct input_dev *dev)
1760 int i; 1835 int i;
1761 unsigned int events; 1836 unsigned int events;
1762 1837
1763 if (dev->mtsize) { 1838 if (dev->mt) {
1764 mt_slots = dev->mtsize; 1839 mt_slots = dev->mt->num_slots;
1765 } else if (test_bit(ABS_MT_TRACKING_ID, dev->absbit)) { 1840 } else if (test_bit(ABS_MT_TRACKING_ID, dev->absbit)) {
1766 mt_slots = dev->absinfo[ABS_MT_TRACKING_ID].maximum - 1841 mt_slots = dev->absinfo[ABS_MT_TRACKING_ID].maximum -
1767 dev->absinfo[ABS_MT_TRACKING_ID].minimum + 1, 1842 dev->absinfo[ABS_MT_TRACKING_ID].minimum + 1,
@@ -1787,6 +1862,9 @@ static unsigned int input_estimate_events_per_packet(struct input_dev *dev)
1787 if (test_bit(i, dev->relbit)) 1862 if (test_bit(i, dev->relbit))
1788 events++; 1863 events++;
1789 1864
1865 /* Make room for KEY and MSC events */
1866 events += 7;
1867
1790 return events; 1868 return events;
1791} 1869}
1792 1870
@@ -1825,6 +1903,7 @@ int input_register_device(struct input_dev *dev)
1825{ 1903{
1826 static atomic_t input_no = ATOMIC_INIT(0); 1904 static atomic_t input_no = ATOMIC_INIT(0);
1827 struct input_handler *handler; 1905 struct input_handler *handler;
1906 unsigned int packet_size;
1828 const char *path; 1907 const char *path;
1829 int error; 1908 int error;
1830 1909
@@ -1837,9 +1916,14 @@ int input_register_device(struct input_dev *dev)
1837 /* Make sure that bitmasks not mentioned in dev->evbit are clean. */ 1916 /* Make sure that bitmasks not mentioned in dev->evbit are clean. */
1838 input_cleanse_bitmasks(dev); 1917 input_cleanse_bitmasks(dev);
1839 1918
1840 if (!dev->hint_events_per_packet) 1919 packet_size = input_estimate_events_per_packet(dev);
1841 dev->hint_events_per_packet = 1920 if (dev->hint_events_per_packet < packet_size)
1842 input_estimate_events_per_packet(dev); 1921 dev->hint_events_per_packet = packet_size;
1922
1923 dev->max_vals = max(dev->hint_events_per_packet, packet_size) + 2;
1924 dev->vals = kcalloc(dev->max_vals, sizeof(*dev->vals), GFP_KERNEL);
1925 if (!dev->vals)
1926 return -ENOMEM;
1843 1927
1844 /* 1928 /*
1845 * If delay and period are pre-set by the driver, then autorepeating 1929 * If delay and period are pre-set by the driver, then autorepeating