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