]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/input/lib/contrib/input/input.c
Inital import
[l4.git] / l4 / pkg / input / lib / contrib / input / input.c
1 /*
2  * The input core
3  *
4  * Copyright (c) 1999-2002 Vojtech Pavlik
5  */
6
7 /*
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU General Public License version 2 as published by
10  * the Free Software Foundation.
11  */
12
13 #include <linux/init.h>
14 #include <linux/sched.h>
15 #include <linux/smp_lock.h>
16 #include <linux/input.h>
17 #include <linux/module.h>
18 #include <linux/random.h>
19 #include <linux/major.h>
20 #include <linux/proc_fs.h>
21 #include <linux/kobject_uevent.h>
22 #include <linux/interrupt.h>
23 #include <linux/poll.h>
24 #include <linux/device.h>
25 #include <linux/devfs_fs_kernel.h>
26
27 MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>");
28 MODULE_DESCRIPTION("Input core");
29 MODULE_LICENSE("GPL");
30
31 EXPORT_SYMBOL(input_register_device);
32 EXPORT_SYMBOL(input_unregister_device);
33 EXPORT_SYMBOL(input_register_handler);
34 EXPORT_SYMBOL(input_unregister_handler);
35 EXPORT_SYMBOL(input_grab_device);
36 EXPORT_SYMBOL(input_release_device);
37 EXPORT_SYMBOL(input_open_device);
38 EXPORT_SYMBOL(input_close_device);
39 EXPORT_SYMBOL(input_accept_process);
40 EXPORT_SYMBOL(input_flush_device);
41 EXPORT_SYMBOL(input_event);
42 EXPORT_SYMBOL(input_class);
43
44 #define INPUT_DEVICES   256
45
46 static LIST_HEAD(input_dev_list);
47 static LIST_HEAD(input_handler_list);
48
49 static struct input_handler *input_table[8];
50
51 #ifdef CONFIG_PROC_FS
52 static struct proc_dir_entry *proc_bus_input_dir;
53 DECLARE_WAIT_QUEUE_HEAD(input_devices_poll_wait);
54 static int input_devices_state;
55 #endif
56
57 static inline unsigned int ms_to_jiffies(unsigned int ms)
58 {
59         unsigned int j;
60         j = (ms * HZ + 500) / 1000;
61         return (j > 0) ? j : 1;
62 }
63
64
65 void input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
66 {
67         struct input_handle *handle;
68
69         if (type > EV_MAX || !test_bit(type, dev->evbit))
70                 return;
71
72         add_input_randomness(type, code, value);
73
74         switch (type) {
75
76                 case EV_SYN:
77                         switch (code) {
78                                 case SYN_CONFIG:
79                                         if (dev->event) dev->event(dev, type, code, value);
80                                         break;
81
82                                 case SYN_REPORT:
83                                         if (dev->sync) return;
84                                         dev->sync = 1;
85                                         break;
86                         }
87                         break;
88
89                 case EV_KEY:
90
91                         if (code > KEY_MAX || !test_bit(code, dev->keybit) || !!test_bit(code, dev->key) == value)
92                                 return;
93
94                         if (value == 2)
95                                 break;
96
97                         change_bit(code, dev->key);
98
99                         if (test_bit(EV_REP, dev->evbit) && dev->rep[REP_PERIOD] && dev->timer.data && value) {
100                                 dev->repeat_key = code;
101                                 mod_timer(&dev->timer, jiffies + ms_to_jiffies(dev->rep[REP_DELAY]));
102                         }
103
104                         break;
105
106                 case EV_ABS:
107
108                         if (code > ABS_MAX || !test_bit(code, dev->absbit))
109                                 return;
110
111                         if (dev->absfuzz[code]) {
112                                 if ((value > dev->abs[code] - (dev->absfuzz[code] >> 1)) &&
113                                     (value < dev->abs[code] + (dev->absfuzz[code] >> 1)))
114                                         return;
115
116                                 if ((value > dev->abs[code] - dev->absfuzz[code]) &&
117                                     (value < dev->abs[code] + dev->absfuzz[code]))
118                                         value = (dev->abs[code] * 3 + value) >> 2;
119
120                                 if ((value > dev->abs[code] - (dev->absfuzz[code] << 1)) &&
121                                     (value < dev->abs[code] + (dev->absfuzz[code] << 1)))
122                                         value = (dev->abs[code] + value) >> 1;
123                         }
124
125                         if (dev->abs[code] == value)
126                                 return;
127
128                         dev->abs[code] = value;
129                         break;
130
131                 case EV_REL:
132
133                         if (code > REL_MAX || !test_bit(code, dev->relbit) || (value == 0))
134                                 return;
135
136                         break;
137
138                 case EV_MSC:
139
140                         if (code > MSC_MAX || !test_bit(code, dev->mscbit))
141                                 return;
142
143                         if (dev->event) dev->event(dev, type, code, value);
144
145                         break;
146
147                 case EV_LED:
148
149                         if (code > LED_MAX || !test_bit(code, dev->ledbit) || !!test_bit(code, dev->led) == value)
150                                 return;
151
152                         change_bit(code, dev->led);
153                         if (dev->event) dev->event(dev, type, code, value);
154
155                         break;
156
157                 case EV_SND:
158
159                         if (code > SND_MAX || !test_bit(code, dev->sndbit))
160                                 return;
161
162                         if (dev->event) dev->event(dev, type, code, value);
163
164                         break;
165
166                 case EV_REP:
167
168                         if (code > REP_MAX || value < 0 || dev->rep[code] == value) return;
169
170                         dev->rep[code] = value;
171                         if (dev->event) dev->event(dev, type, code, value);
172
173                         break;
174
175                 case EV_FF:
176                         if (dev->event) dev->event(dev, type, code, value);
177                         break;
178         }
179
180         if (type != EV_SYN)
181                 dev->sync = 0;
182
183         if (dev->grab)
184                 dev->grab->handler->event(dev->grab, type, code, value);
185         else
186                 list_for_each_entry(handle, &dev->h_list, d_node)
187                         if (handle->open)
188                                 handle->handler->event(handle, type, code, value);
189 }
190
191 static void input_repeat_key(unsigned long data)
192 {
193         struct input_dev *dev = (void *) data;
194
195         if (!test_bit(dev->repeat_key, dev->key))
196                 return;
197
198         input_event(dev, EV_KEY, dev->repeat_key, 2);
199         input_sync(dev);
200
201         mod_timer(&dev->timer, jiffies + ms_to_jiffies(dev->rep[REP_PERIOD]));
202 }
203
204 int input_accept_process(struct input_handle *handle, struct file *file)
205 {
206         if (handle->dev->accept)
207                 return handle->dev->accept(handle->dev, file);
208
209         return 0;
210 }
211
212 int input_grab_device(struct input_handle *handle)
213 {
214         if (handle->dev->grab)
215                 return -EBUSY;
216
217         handle->dev->grab = handle;
218         return 0;
219 }
220
221 void input_release_device(struct input_handle *handle)
222 {
223         if (handle->dev->grab == handle)
224                 handle->dev->grab = NULL;
225 }
226
227 int input_open_device(struct input_handle *handle)
228 {
229         handle->open++;
230         if (handle->dev->open)
231                 return handle->dev->open(handle->dev);
232         return 0;
233 }
234
235 int input_flush_device(struct input_handle* handle, struct file* file)
236 {
237         if (handle->dev->flush)
238                 return handle->dev->flush(handle->dev, file);
239
240         return 0;
241 }
242
243 void input_close_device(struct input_handle *handle)
244 {
245         input_release_device(handle);
246         if (handle->dev->close)
247                 handle->dev->close(handle->dev);
248         handle->open--;
249 }
250
251 static void input_link_handle(struct input_handle *handle)
252 {
253         list_add_tail(&handle->d_node, &handle->dev->h_list);
254         list_add_tail(&handle->h_node, &handle->handler->h_list);
255 }
256
257 #define MATCH_BIT(bit, max) \
258                 for (i = 0; i < NBITS(max); i++) \
259                         if ((id->bit[i] & dev->bit[i]) != id->bit[i]) \
260                                 break; \
261                 if (i != NBITS(max)) \
262                         continue;
263
264 static struct input_device_id *input_match_device(struct input_device_id *id, struct input_dev *dev)
265 {
266         int i;
267
268         for (; id->flags || id->driver_info; id++) {
269
270                 if (id->flags & INPUT_DEVICE_ID_MATCH_BUS)
271                         if (id->id.bustype != dev->id.bustype)
272                                 continue;
273
274                 if (id->flags & INPUT_DEVICE_ID_MATCH_VENDOR)
275                         if (id->id.vendor != dev->id.vendor)
276                                 continue;
277
278                 if (id->flags & INPUT_DEVICE_ID_MATCH_PRODUCT)
279                         if (id->id.product != dev->id.product)
280                                 continue;
281
282                 if (id->flags & INPUT_DEVICE_ID_MATCH_VERSION)
283                         if (id->id.version != dev->id.version)
284                                 continue;
285
286                 MATCH_BIT(evbit,  EV_MAX);
287                 MATCH_BIT(keybit, KEY_MAX);
288                 MATCH_BIT(relbit, REL_MAX);
289                 MATCH_BIT(absbit, ABS_MAX);
290                 MATCH_BIT(mscbit, MSC_MAX);
291                 MATCH_BIT(ledbit, LED_MAX);
292                 MATCH_BIT(sndbit, SND_MAX);
293                 MATCH_BIT(ffbit,  FF_MAX);
294
295                 return id;
296         }
297
298         return NULL;
299 }
300
301 /*
302  * Input hotplugging interface - loading event handlers based on
303  * device bitfields.
304  */
305
306 #ifdef CONFIG_HOTPLUG
307
308 /*
309  * Input hotplugging invokes what /proc/sys/kernel/hotplug says
310  * (normally /sbin/hotplug) when input devices get added or removed.
311  *
312  * This invokes a user mode policy agent, typically helping to load driver
313  * or other modules, configure the device, and more.  Drivers can provide
314  * a MODULE_DEVICE_TABLE to help with module loading subtasks.
315  *
316  */
317
318 #define SPRINTF_BIT_A(bit, name, max) \
319         do { \
320                 envp[i++] = scratch; \
321                 scratch += sprintf(scratch, name); \
322                 for (j = NBITS(max) - 1; j >= 0; j--) \
323                         if (dev->bit[j]) break; \
324                 for (; j >= 0; j--) \
325                         scratch += sprintf(scratch, "%lx ", dev->bit[j]); \
326                 scratch++; \
327         } while (0)
328
329 #define SPRINTF_BIT_A2(bit, name, max, ev) \
330         do { \
331                 if (test_bit(ev, dev->evbit)) \
332                         SPRINTF_BIT_A(bit, name, max); \
333         } while (0)
334
335 static void input_call_hotplug(char *verb, struct input_dev *dev)
336 {
337         char *argv[3], **envp, *buf, *scratch;
338         int i = 0, j, value;
339
340         if (!hotplug_path[0]) {
341                 printk(KERN_ERR "input.c: calling hotplug without a hotplug agent defined\n");
342                 return;
343         }
344         if (in_interrupt()) {
345                 printk(KERN_ERR "input.c: calling hotplug from interrupt\n");
346                 return;
347         }
348         if (!current->fs->root) {
349                 printk(KERN_WARNING "input.c: calling hotplug without valid filesystem\n");
350                 return;
351         }
352         if (!(envp = (char **) kmalloc(20 * sizeof(char *), GFP_KERNEL))) {
353                 printk(KERN_ERR "input.c: not enough memory allocating hotplug environment\n");
354                 return;
355         }
356         if (!(buf = kmalloc(1024, GFP_KERNEL))) {
357                 kfree (envp);
358                 printk(KERN_ERR "input.c: not enough memory allocating hotplug environment\n");
359                 return;
360         }
361
362         argv[0] = hotplug_path;
363         argv[1] = "input";
364         argv[2] = NULL;
365
366         envp[i++] = "HOME=/";
367         envp[i++] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
368
369         scratch = buf;
370
371         envp[i++] = scratch;
372         scratch += sprintf(scratch, "ACTION=%s", verb) + 1;
373
374         envp[i++] = scratch;
375         scratch += sprintf(scratch, "PRODUCT=%x/%x/%x/%x",
376                 dev->id.bustype, dev->id.vendor, dev->id.product, dev->id.version) + 1;
377
378         if (dev->name) {
379                 envp[i++] = scratch;
380                 scratch += sprintf(scratch, "NAME=%s", dev->name) + 1;
381         }
382
383         if (dev->phys) {
384                 envp[i++] = scratch;
385                 scratch += sprintf(scratch, "PHYS=%s", dev->phys) + 1;
386         }
387
388         SPRINTF_BIT_A(evbit, "EV=", EV_MAX);
389         SPRINTF_BIT_A2(keybit, "KEY=", KEY_MAX, EV_KEY);
390         SPRINTF_BIT_A2(relbit, "REL=", REL_MAX, EV_REL);
391         SPRINTF_BIT_A2(absbit, "ABS=", ABS_MAX, EV_ABS);
392         SPRINTF_BIT_A2(mscbit, "MSC=", MSC_MAX, EV_MSC);
393         SPRINTF_BIT_A2(ledbit, "LED=", LED_MAX, EV_LED);
394         SPRINTF_BIT_A2(sndbit, "SND=", SND_MAX, EV_SND);
395         SPRINTF_BIT_A2(ffbit,  "FF=",  FF_MAX, EV_FF);
396
397         envp[i++] = NULL;
398
399 #ifdef INPUT_DEBUG
400         printk(KERN_DEBUG "input.c: calling %s %s [%s %s %s %s %s]\n",
401                 argv[0], argv[1], envp[0], envp[1], envp[2], envp[3], envp[4]);
402 #endif
403
404         value = call_usermodehelper(argv [0], argv, envp, 0);
405
406         kfree(buf);
407         kfree(envp);
408
409 #ifdef INPUT_DEBUG
410         if (value != 0)
411                 printk(KERN_DEBUG "input.c: hotplug returned %d\n", value);
412 #endif
413 }
414
415 #endif
416
417 void input_register_device(struct input_dev *dev)
418 {
419         struct input_handle *handle;
420         struct input_handler *handler;
421         struct input_device_id *id;
422
423         set_bit(EV_SYN, dev->evbit);
424
425         /*
426          * If delay and period are pre-set by the driver, then autorepeating
427          * is handled by the driver itself and we don't do it in input.c.
428          */
429
430         init_timer(&dev->timer);
431         if (!dev->rep[REP_DELAY] && !dev->rep[REP_PERIOD]) {
432                 dev->timer.data = (long) dev;
433                 dev->timer.function = input_repeat_key;
434                 dev->rep[REP_DELAY] = 250;
435                 dev->rep[REP_PERIOD] = 33;
436         }
437
438         INIT_LIST_HEAD(&dev->h_list);
439         list_add_tail(&dev->node, &input_dev_list);
440
441         list_for_each_entry(handler, &input_handler_list, node)
442                 if (!handler->blacklist || !input_match_device(handler->blacklist, dev))
443                         if ((id = input_match_device(handler->id_table, dev)))
444                                 if ((handle = handler->connect(handler, dev, id)))
445                                         input_link_handle(handle);
446
447 #ifdef CONFIG_HOTPLUG
448         input_call_hotplug("add", dev);
449 #endif
450
451 #ifdef CONFIG_PROC_FS
452         input_devices_state++;
453         wake_up(&input_devices_poll_wait);
454 #endif
455 }
456
457 void input_unregister_device(struct input_dev *dev)
458 {
459         struct list_head * node, * next;
460
461         if (!dev) return;
462
463         del_timer_sync(&dev->timer);
464
465         list_for_each_safe(node, next, &dev->h_list) {
466                 struct input_handle * handle = to_handle(node);
467                 list_del_init(&handle->d_node);
468                 list_del_init(&handle->h_node);
469                 handle->handler->disconnect(handle);
470         }
471
472 #ifdef CONFIG_HOTPLUG
473         input_call_hotplug("remove", dev);
474 #endif
475
476         list_del_init(&dev->node);
477
478 #ifdef CONFIG_PROC_FS
479         input_devices_state++;
480         wake_up(&input_devices_poll_wait);
481 #endif
482 }
483
484 void input_register_handler(struct input_handler *handler)
485 {
486         struct input_dev *dev;
487         struct input_handle *handle;
488         struct input_device_id *id;
489
490         if (!handler) return;
491
492         INIT_LIST_HEAD(&handler->h_list);
493
494         if (handler->fops != NULL)
495                 input_table[handler->minor >> 5] = handler;
496
497         list_add_tail(&handler->node, &input_handler_list);
498
499         list_for_each_entry(dev, &input_dev_list, node)
500                 if (!handler->blacklist || !input_match_device(handler->blacklist, dev))
501                         if ((id = input_match_device(handler->id_table, dev)))
502                                 if ((handle = handler->connect(handler, dev, id)))
503                                         input_link_handle(handle);
504
505 #ifdef CONFIG_PROC_FS
506         input_devices_state++;
507         wake_up(&input_devices_poll_wait);
508 #endif
509 }
510
511 void input_unregister_handler(struct input_handler *handler)
512 {
513         struct list_head * node, * next;
514
515         list_for_each_safe(node, next, &handler->h_list) {
516                 struct input_handle * handle = to_handle_h(node);
517                 list_del_init(&handle->h_node);
518                 list_del_init(&handle->d_node);
519                 handler->disconnect(handle);
520         }
521
522         list_del_init(&handler->node);
523
524         if (handler->fops != NULL)
525                 input_table[handler->minor >> 5] = NULL;
526
527 #ifdef CONFIG_PROC_FS
528         input_devices_state++;
529         wake_up(&input_devices_poll_wait);
530 #endif
531 }
532
533 #ifndef L4INPUT
534
535 static int input_open_file(struct inode *inode, struct file *file)
536 {
537         struct input_handler *handler = input_table[iminor(inode) >> 5];
538         struct file_operations *old_fops, *new_fops = NULL;
539         int err;
540
541         /* No load-on-demand here? */
542         if (!handler || !(new_fops = fops_get(handler->fops)))
543                 return -ENODEV;
544
545         /*
546          * That's _really_ odd. Usually NULL ->open means "nothing special",
547          * not "no device". Oh, well...
548          */
549         if (!new_fops->open) {
550                 fops_put(new_fops);
551                 return -ENODEV;
552         }
553         old_fops = file->f_op;
554         file->f_op = new_fops;
555
556         err = new_fops->open(inode, file);
557
558         if (err) {
559                 fops_put(file->f_op);
560                 file->f_op = fops_get(old_fops);
561         }
562         fops_put(old_fops);
563         return err;
564 }
565
566 static struct file_operations input_fops = {
567         .owner = THIS_MODULE,
568         .open = input_open_file,
569 };
570
571 #else
572
573 static int input_open_file(struct inode *inode, struct file *file)
574 {
575         return -EPERM;
576 }
577 static struct file_operations input_fops = {
578         .open = input_open_file,
579 };
580
581 #endif
582
583 #ifdef CONFIG_PROC_FS
584
585 #define SPRINTF_BIT_B(bit, name, max) \
586         do { \
587                 len += sprintf(buf + len, "B: %s", name); \
588                 for (i = NBITS(max) - 1; i >= 0; i--) \
589                         if (dev->bit[i]) break; \
590                 for (; i >= 0; i--) \
591                         len += sprintf(buf + len, "%lx ", dev->bit[i]); \
592                 len += sprintf(buf + len, "\n"); \
593         } while (0)
594
595 #define SPRINTF_BIT_B2(bit, name, max, ev) \
596         do { \
597                 if (test_bit(ev, dev->evbit)) \
598                         SPRINTF_BIT_B(bit, name, max); \
599         } while (0)
600
601
602 static unsigned int input_devices_poll(struct file *file, poll_table *wait)
603 {
604         int state = input_devices_state;
605         poll_wait(file, &input_devices_poll_wait, wait);
606         if (state != input_devices_state)
607                 return POLLIN | POLLRDNORM;
608         return 0;
609 }
610
611 static int input_devices_read(char *buf, char **start, off_t pos, int count, int *eof, void *data)
612 {
613         struct input_dev *dev;
614         struct input_handle *handle;
615
616         off_t at = 0;
617         int i, len, cnt = 0;
618
619         list_for_each_entry(dev, &input_dev_list, node) {
620
621                 len = sprintf(buf, "I: Bus=%04x Vendor=%04x Product=%04x Version=%04x\n",
622                         dev->id.bustype, dev->id.vendor, dev->id.product, dev->id.version);
623
624                 len += sprintf(buf + len, "N: Name=\"%s\"\n", dev->name ? dev->name : "");
625                 len += sprintf(buf + len, "P: Phys=%s\n", dev->phys ? dev->phys : "");
626                 len += sprintf(buf + len, "H: Handlers=");
627
628                 list_for_each_entry(handle, &dev->h_list, d_node)
629                         len += sprintf(buf + len, "%s ", handle->name);
630
631                 len += sprintf(buf + len, "\n");
632
633                 SPRINTF_BIT_B(evbit, "EV=", EV_MAX);
634                 SPRINTF_BIT_B2(keybit, "KEY=", KEY_MAX, EV_KEY);
635                 SPRINTF_BIT_B2(relbit, "REL=", REL_MAX, EV_REL);
636                 SPRINTF_BIT_B2(absbit, "ABS=", ABS_MAX, EV_ABS);
637                 SPRINTF_BIT_B2(mscbit, "MSC=", MSC_MAX, EV_MSC);
638                 SPRINTF_BIT_B2(ledbit, "LED=", LED_MAX, EV_LED);
639                 SPRINTF_BIT_B2(sndbit, "SND=", SND_MAX, EV_SND);
640                 SPRINTF_BIT_B2(ffbit,  "FF=",  FF_MAX, EV_FF);
641
642                 len += sprintf(buf + len, "\n");
643
644                 at += len;
645
646                 if (at >= pos) {
647                         if (!*start) {
648                                 *start = buf + (pos - (at - len));
649                                 cnt = at - pos;
650                         } else  cnt += len;
651                         buf += len;
652                         if (cnt >= count)
653                                 break;
654                 }
655         }
656
657         if (&dev->node == &input_dev_list)
658                 *eof = 1;
659
660         return (count > cnt) ? cnt : count;
661 }
662
663 static int input_handlers_read(char *buf, char **start, off_t pos, int count, int *eof, void *data)
664 {
665         struct input_handler *handler;
666
667         off_t at = 0;
668         int len = 0, cnt = 0;
669         int i = 0;
670
671         list_for_each_entry(handler, &input_handler_list, node) {
672
673                 if (handler->fops)
674                         len = sprintf(buf, "N: Number=%d Name=%s Minor=%d\n",
675                                 i++, handler->name, handler->minor);
676                 else
677                         len = sprintf(buf, "N: Number=%d Name=%s\n",
678                                 i++, handler->name);
679
680                 at += len;
681
682                 if (at >= pos) {
683                         if (!*start) {
684                                 *start = buf + (pos - (at - len));
685                                 cnt = at - pos;
686                         } else  cnt += len;
687                         buf += len;
688                         if (cnt >= count)
689                                 break;
690                 }
691         }
692         if (&handler->node == &input_handler_list)
693                 *eof = 1;
694
695         return (count > cnt) ? cnt : count;
696 }
697
698 static int __init input_proc_init(void)
699 {
700         struct proc_dir_entry *entry;
701
702         proc_bus_input_dir = proc_mkdir("input", proc_bus);
703         if (proc_bus_input_dir == NULL)
704                 return -ENOMEM;
705         proc_bus_input_dir->owner = THIS_MODULE;
706         entry = create_proc_read_entry("devices", 0, proc_bus_input_dir, input_devices_read, NULL);
707         if (entry == NULL) {
708                 remove_proc_entry("input", proc_bus);
709                 return -ENOMEM;
710         }
711         entry->owner = THIS_MODULE;
712         entry->proc_fops->poll = input_devices_poll;
713         entry = create_proc_read_entry("handlers", 0, proc_bus_input_dir, input_handlers_read, NULL);
714         if (entry == NULL) {
715                 remove_proc_entry("devices", proc_bus_input_dir);
716                 remove_proc_entry("input", proc_bus);
717                 return -ENOMEM;
718         }
719         entry->owner = THIS_MODULE;
720         return 0;
721 }
722 #else /* !CONFIG_PROC_FS */
723 static inline int input_proc_init(void) { return 0; }
724 #endif
725
726 struct class_simple *input_class;
727
728 static int __init input_init(void)
729 {
730         int retval = -ENOMEM;
731
732         input_class = class_simple_create(THIS_MODULE, "input");
733 #ifndef L4INPUT
734         if (IS_ERR(input_class))
735                 return PTR_ERR(input_class);
736 #endif
737         input_proc_init();
738         retval = register_chrdev(INPUT_MAJOR, "input", &input_fops);
739         if (retval) {
740                 printk(KERN_ERR "input: unable to register char major %d", INPUT_MAJOR);
741                 remove_proc_entry("devices", proc_bus_input_dir);
742                 remove_proc_entry("handlers", proc_bus_input_dir);
743                 remove_proc_entry("input", proc_bus);
744                 class_simple_destroy(input_class);
745                 return retval;
746         }
747
748         retval = devfs_mk_dir("input");
749         if (retval) {
750                 remove_proc_entry("devices", proc_bus_input_dir);
751                 remove_proc_entry("handlers", proc_bus_input_dir);
752                 remove_proc_entry("input", proc_bus);
753                 unregister_chrdev(INPUT_MAJOR, "input");
754                 class_simple_destroy(input_class);
755         }
756         return retval;
757 }
758
759 static void __exit input_exit(void)
760 {
761         remove_proc_entry("devices", proc_bus_input_dir);
762         remove_proc_entry("handlers", proc_bus_input_dir);
763         remove_proc_entry("input", proc_bus);
764
765         devfs_remove("input");
766         unregister_chrdev(INPUT_MAJOR, "input");
767         class_simple_destroy(input_class);
768 }
769
770 subsys_initcall(input_init);
771 module_exit(input_exit);