Input: psmouse - allow disabing certain protocol extensions
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / input / evdev.c
CommitLineData
1da177e4
LT
1/*
2 * Event char devices, giving access to raw input device events.
3 *
4 * Copyright (c) 1999-2002 Vojtech Pavlik
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.
9 */
10
11#define EVDEV_MINOR_BASE 64
12#define EVDEV_MINORS 32
13#define EVDEV_BUFFER_SIZE 64
14
15#include <linux/poll.h>
16#include <linux/slab.h>
17#include <linux/module.h>
18#include <linux/init.h>
19#include <linux/input.h>
20#include <linux/major.h>
21#include <linux/smp_lock.h>
22#include <linux/device.h>
52658bb6 23#include <linux/compat.h>
1da177e4
LT
24
25struct evdev {
26 int exist;
27 int open;
28 int minor;
29 char name[16];
30 struct input_handle handle;
31 wait_queue_head_t wait;
32 struct evdev_list *grab;
33 struct list_head list;
34};
35
36struct evdev_list {
37 struct input_event buffer[EVDEV_BUFFER_SIZE];
38 int head;
39 int tail;
40 struct fasync_struct *fasync;
41 struct evdev *evdev;
42 struct list_head node;
43};
44
45static struct evdev *evdev_table[EVDEV_MINORS];
46
47static void evdev_event(struct input_handle *handle, unsigned int type, unsigned int code, int value)
48{
49 struct evdev *evdev = handle->private;
50 struct evdev_list *list;
51
52 if (evdev->grab) {
53 list = evdev->grab;
54
55 do_gettimeofday(&list->buffer[list->head].time);
56 list->buffer[list->head].type = type;
57 list->buffer[list->head].code = code;
58 list->buffer[list->head].value = value;
59 list->head = (list->head + 1) & (EVDEV_BUFFER_SIZE - 1);
60
61 kill_fasync(&list->fasync, SIGIO, POLL_IN);
62 } else
63 list_for_each_entry(list, &evdev->list, node) {
64
65 do_gettimeofday(&list->buffer[list->head].time);
66 list->buffer[list->head].type = type;
67 list->buffer[list->head].code = code;
68 list->buffer[list->head].value = value;
69 list->head = (list->head + 1) & (EVDEV_BUFFER_SIZE - 1);
70
71 kill_fasync(&list->fasync, SIGIO, POLL_IN);
72 }
73
74 wake_up_interruptible(&evdev->wait);
75}
76
77static int evdev_fasync(int fd, struct file *file, int on)
78{
79 int retval;
80 struct evdev_list *list = file->private_data;
1e0afb28 81
1da177e4 82 retval = fasync_helper(fd, file, on, &list->fasync);
1e0afb28 83
1da177e4
LT
84 return retval < 0 ? retval : 0;
85}
86
1e0afb28 87static int evdev_flush(struct file *file, fl_owner_t id)
1da177e4
LT
88{
89 struct evdev_list *list = file->private_data;
1e0afb28
DT
90
91 if (!list->evdev->exist)
92 return -ENODEV;
93
1da177e4
LT
94 return input_flush_device(&list->evdev->handle, file);
95}
96
97static void evdev_free(struct evdev *evdev)
98{
99 evdev_table[evdev->minor] = NULL;
100 kfree(evdev);
101}
102
103static int evdev_release(struct inode * inode, struct file * file)
104{
105 struct evdev_list *list = file->private_data;
106
107 if (list->evdev->grab == list) {
108 input_release_device(&list->evdev->handle);
109 list->evdev->grab = NULL;
110 }
111
112 evdev_fasync(-1, file, 0);
113 list_del(&list->node);
114
115 if (!--list->evdev->open) {
116 if (list->evdev->exist)
117 input_close_device(&list->evdev->handle);
118 else
119 evdev_free(list->evdev);
120 }
121
122 kfree(list);
123 return 0;
124}
125
126static int evdev_open(struct inode * inode, struct file * file)
127{
128 struct evdev_list *list;
129 int i = iminor(inode) - EVDEV_MINOR_BASE;
1da177e4
LT
130
131 if (i >= EVDEV_MINORS || !evdev_table[i] || !evdev_table[i]->exist)
132 return -ENODEV;
133
b39787a9 134 if (!(list = kzalloc(sizeof(struct evdev_list), GFP_KERNEL)))
1da177e4 135 return -ENOMEM;
1da177e4
LT
136
137 list->evdev = evdev_table[i];
138 list_add_tail(&list->node, &evdev_table[i]->list);
139 file->private_data = list;
140
141 if (!list->evdev->open++)
142 if (list->evdev->exist)
143 input_open_device(&list->evdev->handle);
144
145 return 0;
146}
147
52658bb6 148#ifdef CONFIG_COMPAT
3a51f7c4 149
52658bb6
JK
150struct input_event_compat {
151 struct compat_timeval time;
152 __u16 type;
153 __u16 code;
154 __s32 value;
155};
156
bf2fcc6f
AK
157/* Note to the author of this code: did it ever occur to
158 you why the ifdefs are needed? Think about it again. -AK */
52658bb6 159#ifdef CONFIG_X86_64
bf2fcc6f 160# define COMPAT_TEST is_compat_task()
52658bb6 161#elif defined(CONFIG_IA64)
6450578f 162# define COMPAT_TEST IS_IA32_PROCESS(task_pt_regs(current))
347a8dc3 163#elif defined(CONFIG_S390)
52658bb6 164# define COMPAT_TEST test_thread_flag(TIF_31BIT)
59df6bbf
RB
165#elif defined(CONFIG_MIPS)
166# define COMPAT_TEST (current->thread.mflags & MF_32BIT_ADDR)
52658bb6
JK
167#else
168# define COMPAT_TEST test_thread_flag(TIF_32BIT)
169#endif
170
3a51f7c4 171static inline size_t evdev_event_size(void)
52658bb6 172{
3a51f7c4
DT
173 return COMPAT_TEST ?
174 sizeof(struct input_event_compat) : sizeof(struct input_event);
175}
52658bb6 176
3a51f7c4
DT
177static int evdev_event_from_user(const char __user *buffer, struct input_event *event)
178{
179 if (COMPAT_TEST) {
180 struct input_event_compat compat_event;
181
182 if (copy_from_user(&compat_event, buffer, sizeof(struct input_event_compat)))
183 return -EFAULT;
184
185 event->time.tv_sec = compat_event.time.tv_sec;
186 event->time.tv_usec = compat_event.time.tv_usec;
187 event->type = compat_event.type;
188 event->code = compat_event.code;
189 event->value = compat_event.value;
190
191 } else {
192 if (copy_from_user(event, buffer, sizeof(struct input_event)))
52658bb6 193 return -EFAULT;
52658bb6
JK
194 }
195
3a51f7c4 196 return 0;
52658bb6 197}
52658bb6 198
3a51f7c4 199static int evdev_event_to_user(char __user *buffer, const struct input_event *event)
1da177e4 200{
3a51f7c4
DT
201 if (COMPAT_TEST) {
202 struct input_event_compat compat_event;
1da177e4 203
3a51f7c4
DT
204 compat_event.time.tv_sec = event->time.tv_sec;
205 compat_event.time.tv_usec = event->time.tv_usec;
206 compat_event.type = event->type;
207 compat_event.code = event->code;
208 compat_event.value = event->value;
52658bb6 209
3a51f7c4
DT
210 if (copy_to_user(buffer, &compat_event, sizeof(struct input_event_compat)))
211 return -EFAULT;
1da177e4 212
3a51f7c4
DT
213 } else {
214 if (copy_to_user(buffer, event, sizeof(struct input_event)))
1da177e4 215 return -EFAULT;
1da177e4
LT
216 }
217
3a51f7c4 218 return 0;
1da177e4
LT
219}
220
3a51f7c4
DT
221#else
222
223static inline size_t evdev_event_size(void)
52658bb6 224{
3a51f7c4
DT
225 return sizeof(struct input_event);
226}
52658bb6 227
3a51f7c4
DT
228static int evdev_event_from_user(const char __user *buffer, struct input_event *event)
229{
230 if (copy_from_user(event, buffer, sizeof(struct input_event)))
231 return -EFAULT;
52658bb6 232
3a51f7c4
DT
233 return 0;
234}
52658bb6 235
3a51f7c4
DT
236static int evdev_event_to_user(char __user *buffer, const struct input_event *event)
237{
238 if (copy_to_user(buffer, event, sizeof(struct input_event)))
239 return -EFAULT;
52658bb6 240
3a51f7c4
DT
241 return 0;
242}
243
244#endif /* CONFIG_COMPAT */
245
246static ssize_t evdev_write(struct file * file, const char __user * buffer, size_t count, loff_t *ppos)
247{
248 struct evdev_list *list = file->private_data;
249 struct input_event event;
250 int retval = 0;
52658bb6
JK
251
252 if (!list->evdev->exist)
253 return -ENODEV;
254
3a51f7c4
DT
255 while (retval < count) {
256
257 if (evdev_event_from_user(buffer + retval, &event))
258 return -EFAULT;
0e739d28 259 input_inject_event(&list->evdev->handle, event.type, event.code, event.value);
3a51f7c4 260 retval += evdev_event_size();
52658bb6
JK
261 }
262
263 return retval;
264}
52658bb6 265
1da177e4
LT
266static ssize_t evdev_read(struct file * file, char __user * buffer, size_t count, loff_t *ppos)
267{
268 struct evdev_list *list = file->private_data;
269 int retval;
270
3a51f7c4 271 if (count < evdev_event_size())
1da177e4
LT
272 return -EINVAL;
273
274 if (list->head == list->tail && list->evdev->exist && (file->f_flags & O_NONBLOCK))
275 return -EAGAIN;
276
277 retval = wait_event_interruptible(list->evdev->wait,
278 list->head != list->tail || (!list->evdev->exist));
279
280 if (retval)
281 return retval;
282
283 if (!list->evdev->exist)
284 return -ENODEV;
285
3a51f7c4
DT
286 while (list->head != list->tail && retval + evdev_event_size() <= count) {
287
288 struct input_event *event = (struct input_event *) list->buffer + list->tail;
289
290 if (evdev_event_to_user(buffer + retval, event))
291 return -EFAULT;
292
1da177e4 293 list->tail = (list->tail + 1) & (EVDEV_BUFFER_SIZE - 1);
3a51f7c4 294 retval += evdev_event_size();
1da177e4
LT
295 }
296
297 return retval;
298}
299
300/* No kernel lock - fine */
301static unsigned int evdev_poll(struct file *file, poll_table *wait)
302{
303 struct evdev_list *list = file->private_data;
1e0afb28 304
1da177e4
LT
305 poll_wait(file, &list->evdev->wait, wait);
306 return ((list->head == list->tail) ? 0 : (POLLIN | POLLRDNORM)) |
307 (list->evdev->exist ? 0 : (POLLHUP | POLLERR));
308}
309
3a51f7c4
DT
310#ifdef CONFIG_COMPAT
311
312#define BITS_PER_LONG_COMPAT (sizeof(compat_long_t) * 8)
313#define NBITS_COMPAT(x) ((((x) - 1) / BITS_PER_LONG_COMPAT) + 1)
314
315#ifdef __BIG_ENDIAN
316static int bits_to_user(unsigned long *bits, unsigned int maxbit,
317 unsigned int maxlen, void __user *p, int compat)
318{
319 int len, i;
320
321 if (compat) {
322 len = NBITS_COMPAT(maxbit) * sizeof(compat_long_t);
323 if (len < maxlen)
324 len = maxlen;
325
326 for (i = 0; i < len / sizeof(compat_long_t); i++)
327 if (copy_to_user((compat_long_t __user *) p + i,
328 (compat_long_t *) bits +
329 i + 1 - ((i % 2) << 1),
330 sizeof(compat_long_t)))
331 return -EFAULT;
332 } else {
333 len = NBITS(maxbit) * sizeof(long);
334 if (len > maxlen)
335 len = maxlen;
336
337 if (copy_to_user(p, bits, len))
338 return -EFAULT;
339 }
340
341 return len;
342}
343#else
344static int bits_to_user(unsigned long *bits, unsigned int maxbit,
345 unsigned int maxlen, void __user *p, int compat)
346{
347 int len = compat ?
348 NBITS_COMPAT(maxbit) * sizeof(compat_long_t) :
349 NBITS(maxbit) * sizeof(long);
350
351 if (len > maxlen)
352 len = maxlen;
353
354 return copy_to_user(p, bits, len) ? -EFAULT : len;
355}
356#endif /* __BIG_ENDIAN */
357
358#else
359
360static int bits_to_user(unsigned long *bits, unsigned int maxbit,
361 unsigned int maxlen, void __user *p, int compat)
362{
363 int len = NBITS(maxbit) * sizeof(long);
364
365 if (len > maxlen)
366 len = maxlen;
367
368 return copy_to_user(p, bits, len) ? -EFAULT : len;
369}
370
371#endif /* CONFIG_COMPAT */
372
373static int str_to_user(const char *str, unsigned int maxlen, void __user *p)
374{
375 int len;
376
377 if (!str)
378 return -ENOENT;
379
380 len = strlen(str) + 1;
381 if (len > maxlen)
382 len = maxlen;
383
384 return copy_to_user(p, str, len) ? -EFAULT : len;
385}
386
387static long evdev_ioctl_handler(struct file *file, unsigned int cmd,
388 void __user *p, int compat_mode)
1da177e4
LT
389{
390 struct evdev_list *list = file->private_data;
391 struct evdev *evdev = list->evdev;
392 struct input_dev *dev = evdev->handle.dev;
393 struct input_absinfo abs;
509ca1a9 394 struct ff_effect effect;
3a51f7c4 395 int __user *ip = (int __user *)p;
1da177e4 396 int i, t, u, v;
509ca1a9 397 int error;
1da177e4 398
3a51f7c4
DT
399 if (!evdev->exist)
400 return -ENODEV;
1da177e4
LT
401
402 switch (cmd) {
403
404 case EVIOCGVERSION:
405 return put_user(EV_VERSION, ip);
406
407 case EVIOCGID:
3a51f7c4
DT
408 if (copy_to_user(p, &dev->id, sizeof(struct input_id)))
409 return -EFAULT;
08791e5c
DT
410 return 0;
411
412 case EVIOCGREP:
413 if (!test_bit(EV_REP, dev->evbit))
414 return -ENOSYS;
415 if (put_user(dev->rep[REP_DELAY], ip))
416 return -EFAULT;
417 if (put_user(dev->rep[REP_PERIOD], ip + 1))
418 return -EFAULT;
419 return 0;
420
421 case EVIOCSREP:
422 if (!test_bit(EV_REP, dev->evbit))
423 return -ENOSYS;
424 if (get_user(u, ip))
425 return -EFAULT;
426 if (get_user(v, ip + 1))
427 return -EFAULT;
428
0e739d28
DT
429 input_inject_event(&evdev->handle, EV_REP, REP_DELAY, u);
430 input_inject_event(&evdev->handle, EV_REP, REP_PERIOD, v);
3a51f7c4
DT
431
432 return 0;
1da177e4
LT
433
434 case EVIOCGKEYCODE:
3a51f7c4
DT
435 if (get_user(t, ip))
436 return -EFAULT;
437 if (t < 0 || t >= dev->keycodemax || !dev->keycodesize)
438 return -EINVAL;
439 if (put_user(INPUT_KEYCODE(dev, t), ip + 1))
440 return -EFAULT;
1da177e4
LT
441 return 0;
442
443 case EVIOCSKEYCODE:
3a51f7c4
DT
444 if (get_user(t, ip))
445 return -EFAULT;
446 if (t < 0 || t >= dev->keycodemax || !dev->keycodesize)
447 return -EINVAL;
448 if (get_user(v, ip + 1))
449 return -EFAULT;
450 if (v < 0 || v > KEY_MAX)
451 return -EINVAL;
452 if (dev->keycodesize < sizeof(v) && (v >> (dev->keycodesize * 8)))
453 return -EINVAL;
454
1da177e4
LT
455 u = SET_INPUT_KEYCODE(dev, t, v);
456 clear_bit(u, dev->keybit);
457 set_bit(v, dev->keybit);
458 for (i = 0; i < dev->keycodemax; i++)
3a51f7c4 459 if (INPUT_KEYCODE(dev, i) == u)
1da177e4 460 set_bit(u, dev->keybit);
3a51f7c4 461
1da177e4
LT
462 return 0;
463
464 case EVIOCSFF:
509ca1a9
AH
465 if (copy_from_user(&effect, p, sizeof(effect)))
466 return -EFAULT;
1da177e4 467
509ca1a9 468 error = input_ff_upload(dev, &effect, file);
3a51f7c4 469
509ca1a9
AH
470 if (put_user(effect.id, &(((struct ff_effect __user *)p)->id)))
471 return -EFAULT;
472
473 return error;
474
475 case EVIOCRMFF:
476 return input_ff_erase(dev, (int)(unsigned long) p, file);
1da177e4
LT
477
478 case EVIOCGEFFECTS:
509ca1a9
AH
479 i = test_bit(EV_FF, dev->evbit) ? dev->ff->max_effects : 0;
480 if (put_user(i, ip))
1da177e4
LT
481 return -EFAULT;
482 return 0;
483
484 case EVIOCGRAB:
3a51f7c4 485 if (p) {
1da177e4
LT
486 if (evdev->grab)
487 return -EBUSY;
488 if (input_grab_device(&evdev->handle))
489 return -EBUSY;
490 evdev->grab = list;
491 return 0;
492 } else {
493 if (evdev->grab != list)
494 return -EINVAL;
495 input_release_device(&evdev->handle);
496 evdev->grab = NULL;
497 return 0;
498 }
499
500 default:
501
41e979f8 502 if (_IOC_TYPE(cmd) != 'E')
1da177e4
LT
503 return -EINVAL;
504
41e979f8
VP
505 if (_IOC_DIR(cmd) == _IOC_READ) {
506
507 if ((_IOC_NR(cmd) & ~EV_MAX) == _IOC_NR(EVIOCGBIT(0,0))) {
508
509 long *bits;
510 int len;
511
512 switch (_IOC_NR(cmd) & EV_MAX) {
513 case 0: bits = dev->evbit; len = EV_MAX; break;
514 case EV_KEY: bits = dev->keybit; len = KEY_MAX; break;
515 case EV_REL: bits = dev->relbit; len = REL_MAX; break;
516 case EV_ABS: bits = dev->absbit; len = ABS_MAX; break;
517 case EV_MSC: bits = dev->mscbit; len = MSC_MAX; break;
518 case EV_LED: bits = dev->ledbit; len = LED_MAX; break;
519 case EV_SND: bits = dev->sndbit; len = SND_MAX; break;
520 case EV_FF: bits = dev->ffbit; len = FF_MAX; break;
31581066 521 case EV_SW: bits = dev->swbit; len = SW_MAX; break;
41e979f8
VP
522 default: return -EINVAL;
523 }
3a51f7c4 524 return bits_to_user(bits, len, _IOC_SIZE(cmd), p, compat_mode);
1da177e4 525 }
1da177e4 526
3a51f7c4
DT
527 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGKEY(0)))
528 return bits_to_user(dev->key, KEY_MAX, _IOC_SIZE(cmd),
529 p, compat_mode);
1da177e4 530
3a51f7c4
DT
531 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGLED(0)))
532 return bits_to_user(dev->led, LED_MAX, _IOC_SIZE(cmd),
533 p, compat_mode);
1da177e4 534
3a51f7c4
DT
535 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGSND(0)))
536 return bits_to_user(dev->snd, SND_MAX, _IOC_SIZE(cmd),
537 p, compat_mode);
1da177e4 538
3a51f7c4
DT
539 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGSW(0)))
540 return bits_to_user(dev->sw, SW_MAX, _IOC_SIZE(cmd),
541 p, compat_mode);
31581066 542
3a51f7c4
DT
543 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGNAME(0)))
544 return str_to_user(dev->name, _IOC_SIZE(cmd), p);
1da177e4 545
3a51f7c4
DT
546 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGPHYS(0)))
547 return str_to_user(dev->phys, _IOC_SIZE(cmd), p);
1da177e4 548
3a51f7c4
DT
549 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGUNIQ(0)))
550 return str_to_user(dev->uniq, _IOC_SIZE(cmd), p);
1da177e4 551
41e979f8 552 if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCGABS(0))) {
1da177e4 553
41e979f8 554 int t = _IOC_NR(cmd) & ABS_MAX;
1da177e4 555
41e979f8
VP
556 abs.value = dev->abs[t];
557 abs.minimum = dev->absmin[t];
558 abs.maximum = dev->absmax[t];
559 abs.fuzz = dev->absfuzz[t];
560 abs.flat = dev->absflat[t];
1da177e4 561
41e979f8
VP
562 if (copy_to_user(p, &abs, sizeof(struct input_absinfo)))
563 return -EFAULT;
564
565 return 0;
566 }
1da177e4 567
1da177e4
LT
568 }
569
41e979f8 570 if (_IOC_DIR(cmd) == _IOC_WRITE) {
1da177e4 571
41e979f8 572 if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCSABS(0))) {
1da177e4 573
41e979f8
VP
574 int t = _IOC_NR(cmd) & ABS_MAX;
575
576 if (copy_from_user(&abs, p, sizeof(struct input_absinfo)))
577 return -EFAULT;
1da177e4 578
41e979f8
VP
579 dev->abs[t] = abs.value;
580 dev->absmin[t] = abs.minimum;
581 dev->absmax[t] = abs.maximum;
582 dev->absfuzz[t] = abs.fuzz;
583 dev->absflat[t] = abs.flat;
1da177e4 584
41e979f8
VP
585 return 0;
586 }
1da177e4 587 }
1da177e4
LT
588 }
589 return -EINVAL;
590}
1da177e4 591
3a51f7c4
DT
592static long evdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
593{
594 return evdev_ioctl_handler(file, cmd, (void __user *)arg, 0);
595}
41e979f8 596
3a51f7c4 597#ifdef CONFIG_COMPAT
52658bb6
JK
598static long evdev_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg)
599{
3a51f7c4 600 return evdev_ioctl_handler(file, cmd, compat_ptr(arg), 1);
1da177e4 601}
52658bb6 602#endif
1da177e4 603
66e66118 604static const struct file_operations evdev_fops = {
1da177e4
LT
605 .owner = THIS_MODULE,
606 .read = evdev_read,
607 .write = evdev_write,
608 .poll = evdev_poll,
609 .open = evdev_open,
610 .release = evdev_release,
52658bb6
JK
611 .unlocked_ioctl = evdev_ioctl,
612#ifdef CONFIG_COMPAT
613 .compat_ioctl = evdev_ioctl_compat,
614#endif
1da177e4
LT
615 .fasync = evdev_fasync,
616 .flush = evdev_flush
617};
618
66e66118
DT
619static struct input_handle *evdev_connect(struct input_handler *handler, struct input_dev *dev,
620 const struct input_device_id *id)
1da177e4
LT
621{
622 struct evdev *evdev;
c9bcd582 623 struct class_device *cdev;
1da177e4
LT
624 int minor;
625
626 for (minor = 0; minor < EVDEV_MINORS && evdev_table[minor]; minor++);
627 if (minor == EVDEV_MINORS) {
628 printk(KERN_ERR "evdev: no more free evdev devices\n");
629 return NULL;
630 }
631
b39787a9 632 if (!(evdev = kzalloc(sizeof(struct evdev), GFP_KERNEL)))
1da177e4 633 return NULL;
1da177e4
LT
634
635 INIT_LIST_HEAD(&evdev->list);
636 init_waitqueue_head(&evdev->wait);
637
638 evdev->exist = 1;
639 evdev->minor = minor;
640 evdev->handle.dev = dev;
641 evdev->handle.name = evdev->name;
642 evdev->handle.handler = handler;
643 evdev->handle.private = evdev;
644 sprintf(evdev->name, "event%d", minor);
645
646 evdev_table[minor] = evdev;
647
c9bcd582 648 cdev = class_device_create(&input_class, &dev->cdev,
1235686f 649 MKDEV(INPUT_MAJOR, EVDEV_MINOR_BASE + minor),
c9bcd582
GKH
650 dev->cdev.dev, evdev->name);
651
652 /* temporary symlink to keep userspace happy */
653 sysfs_create_link(&input_class.subsys.kset.kobj, &cdev->kobj,
654 evdev->name);
1da177e4
LT
655
656 return &evdev->handle;
657}
658
659static void evdev_disconnect(struct input_handle *handle)
660{
661 struct evdev *evdev = handle->private;
662 struct evdev_list *list;
663
c9bcd582 664 sysfs_remove_link(&input_class.subsys.kset.kobj, evdev->name);
ea9f240b 665 class_device_destroy(&input_class,
1235686f 666 MKDEV(INPUT_MAJOR, EVDEV_MINOR_BASE + evdev->minor));
1da177e4
LT
667 evdev->exist = 0;
668
669 if (evdev->open) {
509ca1a9 670 input_flush_device(handle, NULL);
1da177e4
LT
671 input_close_device(handle);
672 wake_up_interruptible(&evdev->wait);
673 list_for_each_entry(list, &evdev->list, node)
674 kill_fasync(&list->fasync, SIGIO, POLL_HUP);
675 } else
676 evdev_free(evdev);
677}
678
66e66118 679static const struct input_device_id evdev_ids[] = {
1da177e4
LT
680 { .driver_info = 1 }, /* Matches all devices */
681 { }, /* Terminating zero entry */
682};
683
684MODULE_DEVICE_TABLE(input, evdev_ids);
685
686static struct input_handler evdev_handler = {
687 .event = evdev_event,
688 .connect = evdev_connect,
689 .disconnect = evdev_disconnect,
690 .fops = &evdev_fops,
691 .minor = EVDEV_MINOR_BASE,
692 .name = "evdev",
693 .id_table = evdev_ids,
694};
695
696static int __init evdev_init(void)
697{
4263cf0f 698 return input_register_handler(&evdev_handler);
1da177e4
LT
699}
700
701static void __exit evdev_exit(void)
702{
703 input_unregister_handler(&evdev_handler);
704}
705
706module_init(evdev_init);
707module_exit(evdev_exit);
708
709MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
710MODULE_DESCRIPTION("Input driver event char devices");
711MODULE_LICENSE("GPL");