upgrade to linux 2.6.10-1.12_FC2
[linux-2.6.git] / drivers / input / mousedev.c
1 /*
2  * Input driver to ExplorerPS/2 device driver module.
3  *
4  * Copyright (c) 1999-2002 Vojtech Pavlik
5  * Copyright (c) 2004      Dmitry Torokhov
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as published by
9  * the Free Software Foundation.
10  */
11
12 #define MOUSEDEV_MINOR_BASE     32
13 #define MOUSEDEV_MINORS         32
14 #define MOUSEDEV_MIX            31
15
16 #include <linux/slab.h>
17 #include <linux/poll.h>
18 #include <linux/module.h>
19 #include <linux/moduleparam.h>
20 #include <linux/init.h>
21 #include <linux/input.h>
22 #include <linux/config.h>
23 #include <linux/smp_lock.h>
24 #include <linux/random.h>
25 #include <linux/major.h>
26 #include <linux/device.h>
27 #include <linux/devfs_fs_kernel.h>
28 #ifdef CONFIG_INPUT_MOUSEDEV_PSAUX
29 #include <linux/miscdevice.h>
30 #endif
31
32 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
33 MODULE_DESCRIPTION("Mouse (ExplorerPS/2) device interfaces");
34 MODULE_LICENSE("GPL");
35
36 #ifndef CONFIG_INPUT_MOUSEDEV_SCREEN_X
37 #define CONFIG_INPUT_MOUSEDEV_SCREEN_X  1024
38 #endif
39 #ifndef CONFIG_INPUT_MOUSEDEV_SCREEN_Y
40 #define CONFIG_INPUT_MOUSEDEV_SCREEN_Y  768
41 #endif
42
43 static int xres = CONFIG_INPUT_MOUSEDEV_SCREEN_X;
44 module_param(xres, uint, 0);
45 MODULE_PARM_DESC(xres, "Horizontal screen resolution");
46
47 static int yres = CONFIG_INPUT_MOUSEDEV_SCREEN_Y;
48 module_param(yres, uint, 0);
49 MODULE_PARM_DESC(yres, "Vertical screen resolution");
50
51 static unsigned tap_time = 200;
52 module_param(tap_time, uint, 0);
53 MODULE_PARM_DESC(tap_time, "Tap time for touchpads in absolute mode (msecs)");
54
55 struct mousedev_hw_data {
56         int dx, dy, dz;
57         int x, y;
58         int abs_event;
59         unsigned long buttons;
60 };
61
62 struct mousedev {
63         int exist;
64         int open;
65         int minor;
66         char name[16];
67         wait_queue_head_t wait;
68         struct list_head list;
69         struct input_handle handle;
70
71         struct mousedev_hw_data packet;
72         unsigned int pkt_count;
73         int old_x[4], old_y[4];
74         unsigned long touch;
75 };
76
77 enum mousedev_emul {
78         MOUSEDEV_EMUL_PS2,
79         MOUSEDEV_EMUL_IMPS,
80         MOUSEDEV_EMUL_EXPS
81 };
82
83 struct mousedev_motion {
84         int dx, dy, dz;
85         unsigned long buttons;
86 };
87
88 #define PACKET_QUEUE_LEN        16
89 struct mousedev_list {
90         struct fasync_struct *fasync;
91         struct mousedev *mousedev;
92         struct list_head node;
93
94         struct mousedev_motion packets[PACKET_QUEUE_LEN];
95         unsigned int head, tail;
96         spinlock_t packet_lock;
97         int pos_x, pos_y;
98
99         signed char ps2[6];
100         unsigned char ready, buffer, bufsiz;
101         unsigned char imexseq, impsseq;
102         enum mousedev_emul mode;
103 };
104
105 #define MOUSEDEV_SEQ_LEN        6
106
107 static unsigned char mousedev_imps_seq[] = { 0xf3, 200, 0xf3, 100, 0xf3, 80 };
108 static unsigned char mousedev_imex_seq[] = { 0xf3, 200, 0xf3, 200, 0xf3, 80 };
109
110 static struct input_handler mousedev_handler;
111
112 static struct mousedev *mousedev_table[MOUSEDEV_MINORS];
113 static struct mousedev mousedev_mix;
114
115 #define fx(i)  (mousedev->old_x[(mousedev->pkt_count - (i)) & 03])
116 #define fy(i)  (mousedev->old_y[(mousedev->pkt_count - (i)) & 03])
117
118 static void mousedev_touchpad_event(struct mousedev *mousedev, unsigned int code, int value)
119 {
120         if (mousedev->touch) {
121                 switch (code) {
122                         case ABS_X:
123                                 fx(0) = value;
124                                 if (mousedev->pkt_count >= 2)
125                                         mousedev->packet.dx = ((fx(0) - fx(1)) / 2 + (fx(1) - fx(2)) / 2) / 8;
126                                 break;
127
128                         case ABS_Y:
129                                 fy(0) = value;
130                                 if (mousedev->pkt_count >= 2)
131                                         mousedev->packet.dy = -((fy(0) - fy(1)) / 2 + (fy(1) - fy(2)) / 2) / 8;
132                                 break;
133                 }
134         }
135 }
136
137 static void mousedev_abs_event(struct input_dev *dev, struct mousedev *mousedev, unsigned int code, int value)
138 {
139         int size;
140
141         switch (code) {
142                 case ABS_X:
143                         size = dev->absmax[ABS_X] - dev->absmin[ABS_X];
144                         if (size == 0) size = xres;
145                         if (value > dev->absmax[ABS_X]) value = dev->absmax[ABS_X];
146                         if (value < dev->absmin[ABS_X]) value = dev->absmin[ABS_X];
147                         mousedev->packet.x = ((value - dev->absmin[ABS_X]) * xres) / size;
148                         mousedev->packet.abs_event = 1;
149                         break;
150
151                 case ABS_Y:
152                         size = dev->absmax[ABS_Y] - dev->absmin[ABS_Y];
153                         if (size == 0) size = yres;
154                         if (value > dev->absmax[ABS_Y]) value = dev->absmax[ABS_Y];
155                         if (value < dev->absmin[ABS_Y]) value = dev->absmin[ABS_Y];
156                         mousedev->packet.y = yres - ((value - dev->absmin[ABS_Y]) * yres) / size;
157                         mousedev->packet.abs_event = 1;
158                         break;
159         }
160 }
161
162 static void mousedev_rel_event(struct mousedev *mousedev, unsigned int code, int value)
163 {
164         switch (code) {
165                 case REL_X:     mousedev->packet.dx += value; break;
166                 case REL_Y:     mousedev->packet.dy -= value; break;
167                 case REL_WHEEL: mousedev->packet.dz -= value; break;
168         }
169 }
170
171 static void mousedev_key_event(struct mousedev *mousedev, unsigned int code, int value)
172 {
173         int index;
174
175         switch (code) {
176                 case BTN_TOUCH:
177                 case BTN_0:
178                 case BTN_FORWARD:
179                 case BTN_LEFT:          index = 0; break;
180                 case BTN_STYLUS:
181                 case BTN_1:
182                 case BTN_RIGHT:         index = 1; break;
183                 case BTN_2:
184                 case BTN_STYLUS2:
185                 case BTN_MIDDLE:        index = 2; break;
186                 case BTN_3:
187                 case BTN_BACK:
188                 case BTN_SIDE:          index = 3; break;
189                 case BTN_4:
190                 case BTN_EXTRA:         index = 4; break;
191                 default:                return;
192         }
193
194         if (value) {
195                 set_bit(index, &mousedev->packet.buttons);
196                 set_bit(index, &mousedev_mix.packet.buttons);
197         } else {
198                 clear_bit(index, &mousedev->packet.buttons);
199                 clear_bit(index, &mousedev_mix.packet.buttons);
200         }
201 }
202
203 static void mousedev_notify_readers(struct mousedev *mousedev, struct mousedev_hw_data *packet)
204 {
205         struct mousedev_list *list;
206         struct mousedev_motion *p;
207         unsigned long flags;
208
209         list_for_each_entry(list, &mousedev->list, node) {
210                 spin_lock_irqsave(&list->packet_lock, flags);
211
212                 p = &list->packets[list->head];
213                 if (list->ready && p->buttons != packet->buttons) {
214                         unsigned int new_head = (list->head + 1) % PACKET_QUEUE_LEN;
215                         if (new_head != list->tail) {
216                                 p = &list->packets[list->head = new_head];
217                                 memset(p, 0, sizeof(struct mousedev_motion));
218                         }
219                 }
220
221                 if (packet->abs_event) {
222                         p->dx += packet->x - list->pos_x;
223                         p->dy += packet->y - list->pos_y;
224                         list->pos_x = packet->x;
225                         list->pos_y = packet->y;
226                 }
227
228                 list->pos_x += packet->dx;
229                 list->pos_x = list->pos_x < 0 ? 0 : (list->pos_x >= xres ? xres : list->pos_x);
230                 list->pos_y += packet->dy;
231                 list->pos_y = list->pos_y < 0 ? 0 : (list->pos_y >= yres ? yres : list->pos_y);
232
233                 p->dx += packet->dx;
234                 p->dy += packet->dy;
235                 p->dz += packet->dz;
236                 p->buttons = mousedev->packet.buttons;
237
238                 list->ready = 1;
239
240                 spin_unlock_irqrestore(&list->packet_lock, flags);
241                 kill_fasync(&list->fasync, SIGIO, POLL_IN);
242         }
243
244         wake_up_interruptible(&mousedev->wait);
245 }
246
247 static void mousedev_touchpad_touch(struct mousedev *mousedev, int value)
248 {
249         if (!value) {
250                 if (mousedev->touch &&
251                     time_before(jiffies, mousedev->touch + msecs_to_jiffies(tap_time))) {
252                         /*
253                          * Toggle left button to emulate tap.
254                          * We rely on the fact that mousedev_mix always has 0
255                          * motion packet so we won't mess current position.
256                          */
257                         set_bit(0, &mousedev->packet.buttons);
258                         set_bit(0, &mousedev_mix.packet.buttons);
259                         mousedev_notify_readers(mousedev, &mousedev_mix.packet);
260                         mousedev_notify_readers(&mousedev_mix, &mousedev_mix.packet);
261                         clear_bit(0, &mousedev->packet.buttons);
262                         clear_bit(0, &mousedev_mix.packet.buttons);
263                 }
264                 mousedev->touch = mousedev->pkt_count = 0;
265         }
266         else
267                 if (!mousedev->touch)
268                         mousedev->touch = jiffies;
269 }
270
271 static void mousedev_event(struct input_handle *handle, unsigned int type, unsigned int code, int value)
272 {
273         struct mousedev *mousedev = handle->private;
274
275         switch (type) {
276                 case EV_ABS:
277                         /* Ignore joysticks */
278                         if (test_bit(BTN_TRIGGER, handle->dev->keybit))
279                                 return;
280
281                         if (test_bit(BTN_TOOL_FINGER, handle->dev->keybit))
282                                 mousedev_touchpad_event(mousedev, code, value);
283                         else
284                                 mousedev_abs_event(handle->dev, mousedev, code, value);
285
286                         break;
287
288                 case EV_REL:
289                         mousedev_rel_event(mousedev, code, value);
290                         break;
291
292                 case EV_KEY:
293                         if (value != 2) {
294                                 if (code == BTN_TOUCH && test_bit(BTN_TOOL_FINGER, handle->dev->keybit))
295                                         mousedev_touchpad_touch(mousedev, value);
296                                 else
297                                         mousedev_key_event(mousedev, code, value);
298                         }
299                         break;
300
301                 case EV_SYN:
302                         if (code == SYN_REPORT) {
303                                 if (mousedev->touch) {
304                                         mousedev->pkt_count++;
305                                         /* Input system eats duplicate events, but we need all of them
306                                          * to do correct averaging so apply present one forward
307                                          */
308                                         fx(0) = fx(1);
309                                         fy(0) = fy(1);
310                                 }
311
312                                 mousedev_notify_readers(mousedev, &mousedev->packet);
313                                 mousedev_notify_readers(&mousedev_mix, &mousedev->packet);
314
315                                 mousedev->packet.dx = mousedev->packet.dy = mousedev->packet.dz = 0;
316                                 mousedev->packet.abs_event = 0;
317                         }
318                         break;
319         }
320 }
321
322 static int mousedev_fasync(int fd, struct file *file, int on)
323 {
324         int retval;
325         struct mousedev_list *list = file->private_data;
326         retval = fasync_helper(fd, file, on, &list->fasync);
327         return retval < 0 ? retval : 0;
328 }
329
330 static void mousedev_free(struct mousedev *mousedev)
331 {
332         mousedev_table[mousedev->minor] = NULL;
333         kfree(mousedev);
334 }
335
336 static int mixdev_release(void)
337 {
338         struct input_handle *handle;
339
340         list_for_each_entry(handle, &mousedev_handler.h_list, h_node) {
341                 struct mousedev *mousedev = handle->private;
342
343                 if (!mousedev->open) {
344                         if (mousedev->exist)
345                                 input_close_device(&mousedev->handle);
346                         else
347                                 mousedev_free(mousedev);
348                 }
349         }
350
351         return 0;
352 }
353
354 static int mousedev_release(struct inode * inode, struct file * file)
355 {
356         struct mousedev_list *list = file->private_data;
357
358         mousedev_fasync(-1, file, 0);
359
360         list_del(&list->node);
361
362         if (!--list->mousedev->open) {
363                 if (list->mousedev->minor == MOUSEDEV_MIX)
364                         return mixdev_release();
365
366                 if (!mousedev_mix.open) {
367                         if (list->mousedev->exist)
368                                 input_close_device(&list->mousedev->handle);
369                         else
370                                 mousedev_free(list->mousedev);
371                 }
372         }
373
374         kfree(list);
375         return 0;
376 }
377
378 static int mousedev_open(struct inode * inode, struct file * file)
379 {
380         struct mousedev_list *list;
381         struct input_handle *handle;
382         struct mousedev *mousedev;
383         int i;
384
385 #ifdef CONFIG_INPUT_MOUSEDEV_PSAUX
386         if (imajor(inode) == MISC_MAJOR)
387                 i = MOUSEDEV_MIX;
388         else
389 #endif
390                 i = iminor(inode) - MOUSEDEV_MINOR_BASE;
391
392         if (i >= MOUSEDEV_MINORS || !mousedev_table[i])
393                 return -ENODEV;
394
395         if (!(list = kmalloc(sizeof(struct mousedev_list), GFP_KERNEL)))
396                 return -ENOMEM;
397         memset(list, 0, sizeof(struct mousedev_list));
398
399         spin_lock_init(&list->packet_lock);
400         list->pos_x = xres / 2;
401         list->pos_y = yres / 2;
402         list->mousedev = mousedev_table[i];
403         list_add_tail(&list->node, &mousedev_table[i]->list);
404         file->private_data = list;
405
406         if (!list->mousedev->open++) {
407                 if (list->mousedev->minor == MOUSEDEV_MIX) {
408                         list_for_each_entry(handle, &mousedev_handler.h_list, h_node) {
409                                 mousedev = handle->private;
410                                 if (!mousedev->open && mousedev->exist)
411                                         input_open_device(handle);
412                         }
413                 } else
414                         if (!mousedev_mix.open && list->mousedev->exist)
415                                 input_open_device(&list->mousedev->handle);
416         }
417
418         return 0;
419 }
420
421 static inline int mousedev_limit_delta(int delta, int limit)
422 {
423         return delta > limit ? limit : (delta < -limit ? -limit : delta);
424 }
425
426 static void mousedev_packet(struct mousedev_list *list, signed char *ps2_data)
427 {
428         struct mousedev_motion *p;
429         unsigned long flags;
430
431         spin_lock_irqsave(&list->packet_lock, flags);
432         p = &list->packets[list->tail];
433
434         ps2_data[0] = 0x08 | ((p->dx < 0) << 4) | ((p->dy < 0) << 5) | (p->buttons & 0x07);
435         ps2_data[1] = mousedev_limit_delta(p->dx, 127);
436         ps2_data[2] = mousedev_limit_delta(p->dy, 127);
437         p->dx -= ps2_data[1];
438         p->dy -= ps2_data[2];
439
440         switch (list->mode) {
441                 case MOUSEDEV_EMUL_EXPS:
442                         ps2_data[3] = mousedev_limit_delta(p->dz, 127);
443                         p->dz -= ps2_data[3];
444                         ps2_data[3] = (ps2_data[3] & 0x0f) | ((p->buttons & 0x18) << 1);
445                         list->bufsiz = 4;
446                         break;
447
448                 case MOUSEDEV_EMUL_IMPS:
449                         ps2_data[0] |= ((p->buttons & 0x10) >> 3) | ((p->buttons & 0x08) >> 1);
450                         ps2_data[3] = mousedev_limit_delta(p->dz, 127);
451                         p->dz -= ps2_data[3];
452                         list->bufsiz = 4;
453                         break;
454
455                 case MOUSEDEV_EMUL_PS2:
456                 default:
457                         ps2_data[0] |= ((p->buttons & 0x10) >> 3) | ((p->buttons & 0x08) >> 1);
458                         p->dz = 0;
459                         list->bufsiz = 3;
460                         break;
461         }
462
463         if (!p->dx && !p->dy && !p->dz) {
464                 if (list->tail != list->head)
465                         list->tail = (list->tail + 1) % PACKET_QUEUE_LEN;
466                 if (list->tail == list->head)
467                         list->ready = 0;
468         }
469
470         spin_unlock_irqrestore(&list->packet_lock, flags);
471 }
472
473
474 static ssize_t mousedev_write(struct file * file, const char __user * buffer, size_t count, loff_t *ppos)
475 {
476         struct mousedev_list *list = file->private_data;
477         unsigned char c;
478         unsigned int i;
479
480         for (i = 0; i < count; i++) {
481
482                 if (get_user(c, buffer + i))
483                         return -EFAULT;
484
485                 if (c == mousedev_imex_seq[list->imexseq]) {
486                         if (++list->imexseq == MOUSEDEV_SEQ_LEN) {
487                                 list->imexseq = 0;
488                                 list->mode = MOUSEDEV_EMUL_EXPS;
489                         }
490                 } else list->imexseq = 0;
491
492                 if (c == mousedev_imps_seq[list->impsseq]) {
493                         if (++list->impsseq == MOUSEDEV_SEQ_LEN) {
494                                 list->impsseq = 0;
495                                 list->mode = MOUSEDEV_EMUL_IMPS;
496                         }
497                 } else list->impsseq = 0;
498
499                 list->ps2[0] = 0xfa;
500
501                 switch (c) {
502
503                         case 0xeb: /* Poll */
504                                 mousedev_packet(list, &list->ps2[1]);
505                                 list->bufsiz++; /* account for leading ACK */
506                                 break;
507
508                         case 0xf2: /* Get ID */
509                                 switch (list->mode) {
510                                         case MOUSEDEV_EMUL_PS2:  list->ps2[1] = 0; break;
511                                         case MOUSEDEV_EMUL_IMPS: list->ps2[1] = 3; break;
512                                         case MOUSEDEV_EMUL_EXPS: list->ps2[1] = 4; break;
513                                 }
514                                 list->bufsiz = 2;
515                                 break;
516
517                         case 0xe9: /* Get info */
518                                 list->ps2[1] = 0x60; list->ps2[2] = 3; list->ps2[3] = 200;
519                                 list->bufsiz = 4;
520                                 break;
521
522                         case 0xff: /* Reset */
523                                 list->impsseq = list->imexseq = 0;
524                                 list->mode = MOUSEDEV_EMUL_PS2;
525                                 list->ps2[1] = 0xaa; list->ps2[2] = 0x00;
526                                 list->bufsiz = 3;
527                                 break;
528
529                         default:
530                                 list->bufsiz = 1;
531                                 break;
532                 }
533
534                 list->buffer = list->bufsiz;
535         }
536
537         kill_fasync(&list->fasync, SIGIO, POLL_IN);
538
539         wake_up_interruptible(&list->mousedev->wait);
540
541         return count;
542 }
543
544 static ssize_t mousedev_read(struct file * file, char __user * buffer, size_t count, loff_t *ppos)
545 {
546         struct mousedev_list *list = file->private_data;
547         int retval = 0;
548
549         if (!list->ready && !list->buffer && (file->f_flags & O_NONBLOCK))
550                 return -EAGAIN;
551
552         retval = wait_event_interruptible(list->mousedev->wait,
553                                           !list->mousedev->exist || list->ready || list->buffer);
554
555         if (retval)
556                 return retval;
557
558         if (!list->mousedev->exist)
559                 return -ENODEV;
560
561         if (!list->buffer && list->ready) {
562                 mousedev_packet(list, list->ps2);
563                 list->buffer = list->bufsiz;
564         }
565
566         if (count > list->buffer)
567                 count = list->buffer;
568
569         list->buffer -= count;
570
571         if (copy_to_user(buffer, list->ps2 + list->bufsiz - list->buffer - count, count))
572                 return -EFAULT;
573
574         return count;
575 }
576
577 /* No kernel lock - fine */
578 static unsigned int mousedev_poll(struct file *file, poll_table *wait)
579 {
580         struct mousedev_list *list = file->private_data;
581         poll_wait(file, &list->mousedev->wait, wait);
582         if (list->ready || list->buffer)
583                 return POLLIN | POLLRDNORM;
584         return 0;
585 }
586
587 struct file_operations mousedev_fops = {
588         .owner =        THIS_MODULE,
589         .read =         mousedev_read,
590         .write =        mousedev_write,
591         .poll =         mousedev_poll,
592         .open =         mousedev_open,
593         .release =      mousedev_release,
594         .fasync =       mousedev_fasync,
595 };
596
597 static struct input_handle *mousedev_connect(struct input_handler *handler, struct input_dev *dev, struct input_device_id *id)
598 {
599         struct mousedev *mousedev;
600         int minor = 0;
601
602         for (minor = 0; minor < MOUSEDEV_MINORS && mousedev_table[minor]; minor++);
603         if (minor == MOUSEDEV_MINORS) {
604                 printk(KERN_ERR "mousedev: no more free mousedev devices\n");
605                 return NULL;
606         }
607
608         if (!(mousedev = kmalloc(sizeof(struct mousedev), GFP_KERNEL)))
609                 return NULL;
610         memset(mousedev, 0, sizeof(struct mousedev));
611
612         INIT_LIST_HEAD(&mousedev->list);
613         init_waitqueue_head(&mousedev->wait);
614
615         mousedev->minor = minor;
616         mousedev->exist = 1;
617         mousedev->handle.dev = dev;
618         mousedev->handle.name = mousedev->name;
619         mousedev->handle.handler = handler;
620         mousedev->handle.private = mousedev;
621         sprintf(mousedev->name, "mouse%d", minor);
622
623         if (mousedev_mix.open)
624                 input_open_device(&mousedev->handle);
625
626         mousedev_table[minor] = mousedev;
627
628         devfs_mk_cdev(MKDEV(INPUT_MAJOR, MOUSEDEV_MINOR_BASE + minor),
629                         S_IFCHR|S_IRUGO|S_IWUSR, "input/mouse%d", minor);
630         class_simple_device_add(input_class,
631                                 MKDEV(INPUT_MAJOR, MOUSEDEV_MINOR_BASE + minor),
632                                 dev->dev, "mouse%d", minor);
633
634         return &mousedev->handle;
635 }
636
637 static void mousedev_disconnect(struct input_handle *handle)
638 {
639         struct mousedev *mousedev = handle->private;
640
641         class_simple_device_remove(MKDEV(INPUT_MAJOR, MOUSEDEV_MINOR_BASE + mousedev->minor));
642         devfs_remove("input/mouse%d", mousedev->minor);
643         mousedev->exist = 0;
644
645         if (mousedev->open) {
646                 input_close_device(handle);
647         } else {
648                 if (mousedev_mix.open)
649                         input_close_device(handle);
650                 mousedev_free(mousedev);
651         }
652 }
653
654 static struct input_device_id mousedev_ids[] = {
655         {
656                 .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_KEYBIT | INPUT_DEVICE_ID_MATCH_RELBIT,
657                 .evbit = { BIT(EV_KEY) | BIT(EV_REL) },
658                 .keybit = { [LONG(BTN_LEFT)] = BIT(BTN_LEFT) },
659                 .relbit = { BIT(REL_X) | BIT(REL_Y) },
660         },      /* A mouse like device, at least one button, two relative axes */
661         {
662                 .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_RELBIT,
663                 .evbit = { BIT(EV_KEY) | BIT(EV_REL) },
664                 .relbit = { BIT(REL_WHEEL) },
665         },      /* A separate scrollwheel */
666         {
667                 .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_KEYBIT | INPUT_DEVICE_ID_MATCH_ABSBIT,
668                 .evbit = { BIT(EV_KEY) | BIT(EV_ABS) },
669                 .keybit = { [LONG(BTN_TOUCH)] = BIT(BTN_TOUCH) },
670                 .absbit = { BIT(ABS_X) | BIT(ABS_Y) },
671         },      /* A tablet like device, at least touch detection, two absolute axes */
672         {
673                 .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_KEYBIT | INPUT_DEVICE_ID_MATCH_ABSBIT,
674                 .evbit = { BIT(EV_KEY) | BIT(EV_ABS) },
675                 .keybit = { [LONG(BTN_TOOL_FINGER)] = BIT(BTN_TOOL_FINGER) },
676                 .absbit = { BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE) | BIT(ABS_TOOL_WIDTH) },
677         },      /* A touchpad */
678
679         { },    /* Terminating entry */
680 };
681
682 MODULE_DEVICE_TABLE(input, mousedev_ids);
683
684 static struct input_handler mousedev_handler = {
685         .event =        mousedev_event,
686         .connect =      mousedev_connect,
687         .disconnect =   mousedev_disconnect,
688         .fops =         &mousedev_fops,
689         .minor =        MOUSEDEV_MINOR_BASE,
690         .name =         "mousedev",
691         .id_table =     mousedev_ids,
692 };
693
694 #ifdef CONFIG_INPUT_MOUSEDEV_PSAUX
695 static struct miscdevice psaux_mouse = {
696         PSMOUSE_MINOR, "psaux", &mousedev_fops
697 };
698 static int psaux_registered;
699 #endif
700
701 static int __init mousedev_init(void)
702 {
703         input_register_handler(&mousedev_handler);
704
705         memset(&mousedev_mix, 0, sizeof(struct mousedev));
706         INIT_LIST_HEAD(&mousedev_mix.list);
707         init_waitqueue_head(&mousedev_mix.wait);
708         mousedev_table[MOUSEDEV_MIX] = &mousedev_mix;
709         mousedev_mix.exist = 1;
710         mousedev_mix.minor = MOUSEDEV_MIX;
711
712         devfs_mk_cdev(MKDEV(INPUT_MAJOR, MOUSEDEV_MINOR_BASE + MOUSEDEV_MIX),
713                         S_IFCHR|S_IRUGO|S_IWUSR, "input/mice");
714         class_simple_device_add(input_class, MKDEV(INPUT_MAJOR, MOUSEDEV_MINOR_BASE + MOUSEDEV_MIX),
715                                 NULL, "mice");
716
717 #ifdef CONFIG_INPUT_MOUSEDEV_PSAUX
718         if (!(psaux_registered = !misc_register(&psaux_mouse)))
719                 printk(KERN_WARNING "mice: could not misc_register the device\n");
720 #endif
721
722         printk(KERN_INFO "mice: PS/2 mouse device common for all mice\n");
723
724         return 0;
725 }
726
727 static void __exit mousedev_exit(void)
728 {
729 #ifdef CONFIG_INPUT_MOUSEDEV_PSAUX
730         if (psaux_registered)
731                 misc_deregister(&psaux_mouse);
732 #endif
733         devfs_remove("input/mice");
734         class_simple_device_remove(MKDEV(INPUT_MAJOR, MOUSEDEV_MINOR_BASE + MOUSEDEV_MIX));
735         input_unregister_handler(&mousedev_handler);
736 }
737
738 module_init(mousedev_init);
739 module_exit(mousedev_exit);