blob: db52ba0a316f97e4ae8713aa33c5daf2f11e15ad [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Dmitry Torokhov969b21c2006-04-02 00:09:34 -050021#include <linux/seq_file.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/interrupt.h>
23#include <linux/poll.h>
24#include <linux/device.h>
Jes Sorensene676c232006-02-19 00:21:46 -050025#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
27MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>");
28MODULE_DESCRIPTION("Input core");
29MODULE_LICENSE("GPL");
30
Dmitry Torokhovd19fbe82005-09-15 02:01:39 -050031EXPORT_SYMBOL(input_allocate_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -070032EXPORT_SYMBOL(input_register_device);
33EXPORT_SYMBOL(input_unregister_device);
34EXPORT_SYMBOL(input_register_handler);
35EXPORT_SYMBOL(input_unregister_handler);
36EXPORT_SYMBOL(input_grab_device);
37EXPORT_SYMBOL(input_release_device);
38EXPORT_SYMBOL(input_open_device);
39EXPORT_SYMBOL(input_close_device);
40EXPORT_SYMBOL(input_accept_process);
41EXPORT_SYMBOL(input_flush_device);
42EXPORT_SYMBOL(input_event);
Greg Kroah-Hartmanea9f2402005-10-27 22:25:43 -070043EXPORT_SYMBOL_GPL(input_class);
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45#define INPUT_DEVICES 256
46
47static LIST_HEAD(input_dev_list);
48static LIST_HEAD(input_handler_list);
49
50static struct input_handler *input_table[8];
51
Linus Torvalds1da177e2005-04-16 15:20:36 -070052void input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
53{
54 struct input_handle *handle;
55
56 if (type > EV_MAX || !test_bit(type, dev->evbit))
57 return;
58
59 add_input_randomness(type, code, value);
60
61 switch (type) {
62
63 case EV_SYN:
64 switch (code) {
65 case SYN_CONFIG:
66 if (dev->event) dev->event(dev, type, code, value);
67 break;
68
69 case SYN_REPORT:
70 if (dev->sync) return;
71 dev->sync = 1;
72 break;
73 }
74 break;
75
76 case EV_KEY:
77
78 if (code > KEY_MAX || !test_bit(code, dev->keybit) || !!test_bit(code, dev->key) == value)
79 return;
80
81 if (value == 2)
82 break;
83
84 change_bit(code, dev->key);
85
86 if (test_bit(EV_REP, dev->evbit) && dev->rep[REP_PERIOD] && dev->rep[REP_DELAY] && dev->timer.data && value) {
87 dev->repeat_key = code;
88 mod_timer(&dev->timer, jiffies + msecs_to_jiffies(dev->rep[REP_DELAY]));
89 }
90
91 break;
92
Richard Purdie31581062005-09-06 15:19:06 -070093 case EV_SW:
94
95 if (code > SW_MAX || !test_bit(code, dev->swbit) || !!test_bit(code, dev->sw) == value)
96 return;
97
98 change_bit(code, dev->sw);
99
100 break;
101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 case EV_ABS:
103
104 if (code > ABS_MAX || !test_bit(code, dev->absbit))
105 return;
106
107 if (dev->absfuzz[code]) {
108 if ((value > dev->abs[code] - (dev->absfuzz[code] >> 1)) &&
109 (value < dev->abs[code] + (dev->absfuzz[code] >> 1)))
110 return;
111
112 if ((value > dev->abs[code] - dev->absfuzz[code]) &&
113 (value < dev->abs[code] + dev->absfuzz[code]))
114 value = (dev->abs[code] * 3 + value) >> 2;
115
116 if ((value > dev->abs[code] - (dev->absfuzz[code] << 1)) &&
117 (value < dev->abs[code] + (dev->absfuzz[code] << 1)))
118 value = (dev->abs[code] + value) >> 1;
119 }
120
121 if (dev->abs[code] == value)
122 return;
123
124 dev->abs[code] = value;
125 break;
126
127 case EV_REL:
128
129 if (code > REL_MAX || !test_bit(code, dev->relbit) || (value == 0))
130 return;
131
132 break;
133
134 case EV_MSC:
135
136 if (code > MSC_MAX || !test_bit(code, dev->mscbit))
137 return;
138
139 if (dev->event) dev->event(dev, type, code, value);
140
141 break;
142
143 case EV_LED:
144
145 if (code > LED_MAX || !test_bit(code, dev->ledbit) || !!test_bit(code, dev->led) == value)
146 return;
147
148 change_bit(code, dev->led);
149 if (dev->event) dev->event(dev, type, code, value);
150
151 break;
152
153 case EV_SND:
154
155 if (code > SND_MAX || !test_bit(code, dev->sndbit))
156 return;
157
158 if (dev->event) dev->event(dev, type, code, value);
159
160 break;
161
162 case EV_REP:
163
164 if (code > REP_MAX || value < 0 || dev->rep[code] == value) return;
165
166 dev->rep[code] = value;
167 if (dev->event) dev->event(dev, type, code, value);
168
169 break;
170
171 case EV_FF:
172 if (dev->event) dev->event(dev, type, code, value);
173 break;
174 }
175
176 if (type != EV_SYN)
177 dev->sync = 0;
178
179 if (dev->grab)
180 dev->grab->handler->event(dev->grab, type, code, value);
181 else
182 list_for_each_entry(handle, &dev->h_list, d_node)
183 if (handle->open)
184 handle->handler->event(handle, type, code, value);
185}
186
187static void input_repeat_key(unsigned long data)
188{
189 struct input_dev *dev = (void *) data;
190
191 if (!test_bit(dev->repeat_key, dev->key))
192 return;
193
194 input_event(dev, EV_KEY, dev->repeat_key, 2);
195 input_sync(dev);
196
197 if (dev->rep[REP_PERIOD])
198 mod_timer(&dev->timer, jiffies + msecs_to_jiffies(dev->rep[REP_PERIOD]));
199}
200
201int input_accept_process(struct input_handle *handle, struct file *file)
202{
203 if (handle->dev->accept)
204 return handle->dev->accept(handle->dev, file);
205
206 return 0;
207}
208
209int input_grab_device(struct input_handle *handle)
210{
211 if (handle->dev->grab)
212 return -EBUSY;
213
214 handle->dev->grab = handle;
215 return 0;
216}
217
218void input_release_device(struct input_handle *handle)
219{
220 if (handle->dev->grab == handle)
221 handle->dev->grab = NULL;
222}
223
224int input_open_device(struct input_handle *handle)
225{
Dmitry Torokhov0fbf87c2005-05-29 02:29:25 -0500226 struct input_dev *dev = handle->dev;
227 int err;
228
Jes Sorensene676c232006-02-19 00:21:46 -0500229 err = mutex_lock_interruptible(&dev->mutex);
Dmitry Torokhov0fbf87c2005-05-29 02:29:25 -0500230 if (err)
231 return err;
232
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 handle->open++;
Dmitry Torokhov0fbf87c2005-05-29 02:29:25 -0500234
235 if (!dev->users++ && dev->open)
236 err = dev->open(dev);
237
238 if (err)
239 handle->open--;
240
Jes Sorensene676c232006-02-19 00:21:46 -0500241 mutex_unlock(&dev->mutex);
Dmitry Torokhov0fbf87c2005-05-29 02:29:25 -0500242
243 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244}
245
246int input_flush_device(struct input_handle* handle, struct file* file)
247{
248 if (handle->dev->flush)
249 return handle->dev->flush(handle->dev, file);
250
251 return 0;
252}
253
254void input_close_device(struct input_handle *handle)
255{
Dmitry Torokhov0fbf87c2005-05-29 02:29:25 -0500256 struct input_dev *dev = handle->dev;
257
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 input_release_device(handle);
Dmitry Torokhov0fbf87c2005-05-29 02:29:25 -0500259
Jes Sorensene676c232006-02-19 00:21:46 -0500260 mutex_lock(&dev->mutex);
Dmitry Torokhov0fbf87c2005-05-29 02:29:25 -0500261
262 if (!--dev->users && dev->close)
263 dev->close(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 handle->open--;
Dmitry Torokhov0fbf87c2005-05-29 02:29:25 -0500265
Jes Sorensene676c232006-02-19 00:21:46 -0500266 mutex_unlock(&dev->mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267}
268
269static void input_link_handle(struct input_handle *handle)
270{
271 list_add_tail(&handle->d_node, &handle->dev->h_list);
272 list_add_tail(&handle->h_node, &handle->handler->h_list);
273}
274
275#define MATCH_BIT(bit, max) \
276 for (i = 0; i < NBITS(max); i++) \
277 if ((id->bit[i] & dev->bit[i]) != id->bit[i]) \
278 break; \
279 if (i != NBITS(max)) \
280 continue;
281
282static struct input_device_id *input_match_device(struct input_device_id *id, struct input_dev *dev)
283{
284 int i;
285
286 for (; id->flags || id->driver_info; id++) {
287
288 if (id->flags & INPUT_DEVICE_ID_MATCH_BUS)
289 if (id->id.bustype != dev->id.bustype)
290 continue;
291
292 if (id->flags & INPUT_DEVICE_ID_MATCH_VENDOR)
293 if (id->id.vendor != dev->id.vendor)
294 continue;
295
296 if (id->flags & INPUT_DEVICE_ID_MATCH_PRODUCT)
297 if (id->id.product != dev->id.product)
298 continue;
299
300 if (id->flags & INPUT_DEVICE_ID_MATCH_VERSION)
301 if (id->id.version != dev->id.version)
302 continue;
303
304 MATCH_BIT(evbit, EV_MAX);
305 MATCH_BIT(keybit, KEY_MAX);
306 MATCH_BIT(relbit, REL_MAX);
307 MATCH_BIT(absbit, ABS_MAX);
308 MATCH_BIT(mscbit, MSC_MAX);
309 MATCH_BIT(ledbit, LED_MAX);
310 MATCH_BIT(sndbit, SND_MAX);
311 MATCH_BIT(ffbit, FF_MAX);
Dmitry Torokhovff13f982005-09-24 02:02:29 -0500312 MATCH_BIT(swbit, SW_MAX);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
314 return id;
315 }
316
317 return NULL;
318}
319
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320#ifdef CONFIG_PROC_FS
Dmitry Torokhovf96b4342005-06-30 00:50:29 -0500321
322static struct proc_dir_entry *proc_bus_input_dir;
323static DECLARE_WAIT_QUEUE_HEAD(input_devices_poll_wait);
324static int input_devices_state;
325
326static inline void input_wakeup_procfs_readers(void)
327{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 input_devices_state++;
329 wake_up(&input_devices_poll_wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330}
331
Dmitry Torokhov969b21c2006-04-02 00:09:34 -0500332static unsigned int input_proc_devices_poll(struct file *file, poll_table *wait)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333{
Dmitry Torokhovf96b4342005-06-30 00:50:29 -0500334 int state = input_devices_state;
335 poll_wait(file, &input_devices_poll_wait, wait);
336 if (state != input_devices_state)
337 return POLLIN | POLLRDNORM;
338 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339}
340
Dmitry Torokhov969b21c2006-04-02 00:09:34 -0500341static struct list_head *list_get_nth_element(struct list_head *list, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342{
Dmitry Torokhov969b21c2006-04-02 00:09:34 -0500343 struct list_head *node;
344 loff_t i = 0;
345
346 list_for_each(node, list)
347 if (i++ == *pos)
348 return node;
349
350 return NULL;
351}
352
353static struct list_head *list_get_next_element(struct list_head *list, struct list_head *element, loff_t *pos)
354{
355 if (element->next == list)
356 return NULL;
357
358 ++(*pos);
359 return element->next;
360}
361
362static void *input_devices_seq_start(struct seq_file *seq, loff_t *pos)
363{
364 /* acquire lock here ... Yes, we do need locking, I knowi, I know... */
365
366 return list_get_nth_element(&input_dev_list, pos);
367}
368
369static void *input_devices_seq_next(struct seq_file *seq, void *v, loff_t *pos)
370{
371 return list_get_next_element(&input_dev_list, v, pos);
372}
373
374static void input_devices_seq_stop(struct seq_file *seq, void *v)
375{
376 /* release lock here */
377}
378
379static void input_seq_print_bitmap(struct seq_file *seq, const char *name,
380 unsigned long *bitmap, int max)
381{
382 int i;
383
384 for (i = NBITS(max) - 1; i > 0; i--)
385 if (bitmap[i])
386 break;
387
388 seq_printf(seq, "B: %s=", name);
389 for (; i >= 0; i--)
390 seq_printf(seq, "%lx%s", bitmap[i], i > 0 ? " " : "");
391 seq_putc(seq, '\n');
392}
393
394static int input_devices_seq_show(struct seq_file *seq, void *v)
395{
396 struct input_dev *dev = container_of(v, struct input_dev, node);
397 const char *path = kobject_get_path(&dev->cdev.kobj, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 struct input_handle *handle;
399
Dmitry Torokhov969b21c2006-04-02 00:09:34 -0500400 seq_printf(seq, "I: Bus=%04x Vendor=%04x Product=%04x Version=%04x\n",
401 dev->id.bustype, dev->id.vendor, dev->id.product, dev->id.version);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Dmitry Torokhov969b21c2006-04-02 00:09:34 -0500403 seq_printf(seq, "N: Name=\"%s\"\n", dev->name ? dev->name : "");
404 seq_printf(seq, "P: Phys=%s\n", dev->phys ? dev->phys : "");
405 seq_printf(seq, "S: Sysfs=%s\n", path ? path : "");
406 seq_printf(seq, "H: Handlers=");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
Dmitry Torokhov969b21c2006-04-02 00:09:34 -0500408 list_for_each_entry(handle, &dev->h_list, d_node)
409 seq_printf(seq, "%s ", handle->name);
410 seq_putc(seq, '\n');
Dmitry Torokhov051b2fe2005-09-15 02:01:54 -0500411
Dmitry Torokhov969b21c2006-04-02 00:09:34 -0500412 input_seq_print_bitmap(seq, "EV", dev->evbit, EV_MAX);
413 if (test_bit(EV_KEY, dev->evbit))
414 input_seq_print_bitmap(seq, "KEY", dev->keybit, KEY_MAX);
415 if (test_bit(EV_REL, dev->evbit))
416 input_seq_print_bitmap(seq, "REL", dev->relbit, REL_MAX);
417 if (test_bit(EV_ABS, dev->evbit))
418 input_seq_print_bitmap(seq, "ABS", dev->absbit, ABS_MAX);
419 if (test_bit(EV_MSC, dev->evbit))
420 input_seq_print_bitmap(seq, "MSC", dev->mscbit, MSC_MAX);
421 if (test_bit(EV_LED, dev->evbit))
422 input_seq_print_bitmap(seq, "LED", dev->ledbit, LED_MAX);
423 if (test_bit(EV_SND, dev->evbit))
424 input_seq_print_bitmap(seq, "SND", dev->sndbit, SND_MAX);
425 if (test_bit(EV_FF, dev->evbit))
426 input_seq_print_bitmap(seq, "FF", dev->ffbit, FF_MAX);
427 if (test_bit(EV_SW, dev->evbit))
428 input_seq_print_bitmap(seq, "SW", dev->swbit, SW_MAX);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
Dmitry Torokhov969b21c2006-04-02 00:09:34 -0500430 seq_putc(seq, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
Dmitry Torokhov969b21c2006-04-02 00:09:34 -0500432 kfree(path);
433 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434}
435
Dmitry Torokhov969b21c2006-04-02 00:09:34 -0500436static struct seq_operations input_devices_seq_ops = {
437 .start = input_devices_seq_start,
438 .next = input_devices_seq_next,
439 .stop = input_devices_seq_stop,
440 .show = input_devices_seq_show,
441};
442
443static int input_proc_devices_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444{
Dmitry Torokhov969b21c2006-04-02 00:09:34 -0500445 return seq_open(file, &input_devices_seq_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446}
447
Dmitry Torokhov969b21c2006-04-02 00:09:34 -0500448static struct file_operations input_devices_fileops = {
449 .owner = THIS_MODULE,
450 .open = input_proc_devices_open,
451 .poll = input_proc_devices_poll,
452 .read = seq_read,
453 .llseek = seq_lseek,
454 .release = seq_release,
455};
456
457static void *input_handlers_seq_start(struct seq_file *seq, loff_t *pos)
458{
459 /* acquire lock here ... Yes, we do need locking, I knowi, I know... */
460 seq->private = (void *)(unsigned long)*pos;
461 return list_get_nth_element(&input_handler_list, pos);
462}
463
464static void *input_handlers_seq_next(struct seq_file *seq, void *v, loff_t *pos)
465{
466 seq->private = (void *)(unsigned long)(*pos + 1);
467 return list_get_next_element(&input_handler_list, v, pos);
468}
469
470static void input_handlers_seq_stop(struct seq_file *seq, void *v)
471{
472 /* release lock here */
473}
474
475static int input_handlers_seq_show(struct seq_file *seq, void *v)
476{
477 struct input_handler *handler = container_of(v, struct input_handler, node);
478
479 seq_printf(seq, "N: Number=%ld Name=%s",
480 (unsigned long)seq->private, handler->name);
481 if (handler->fops)
482 seq_printf(seq, " Minor=%d", handler->minor);
483 seq_putc(seq, '\n');
484
485 return 0;
486}
487static struct seq_operations input_handlers_seq_ops = {
488 .start = input_handlers_seq_start,
489 .next = input_handlers_seq_next,
490 .stop = input_handlers_seq_stop,
491 .show = input_handlers_seq_show,
492};
493
494static int input_proc_handlers_open(struct inode *inode, struct file *file)
495{
496 return seq_open(file, &input_handlers_seq_ops);
497}
498
499static struct file_operations input_handlers_fileops = {
500 .owner = THIS_MODULE,
501 .open = input_proc_handlers_open,
502 .read = seq_read,
503 .llseek = seq_lseek,
504 .release = seq_release,
505};
Luke Kosewskie334016fc2005-06-01 02:39:28 -0500506
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507static int __init input_proc_init(void)
508{
509 struct proc_dir_entry *entry;
510
511 proc_bus_input_dir = proc_mkdir("input", proc_bus);
Dmitry Torokhovf96b4342005-06-30 00:50:29 -0500512 if (!proc_bus_input_dir)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 return -ENOMEM;
Dmitry Torokhovf96b4342005-06-30 00:50:29 -0500514
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 proc_bus_input_dir->owner = THIS_MODULE;
Dmitry Torokhovf96b4342005-06-30 00:50:29 -0500516
Dmitry Torokhov969b21c2006-04-02 00:09:34 -0500517 entry = create_proc_entry("devices", 0, proc_bus_input_dir);
Dmitry Torokhovf96b4342005-06-30 00:50:29 -0500518 if (!entry)
519 goto fail1;
520
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 entry->owner = THIS_MODULE;
Dmitry Torokhov969b21c2006-04-02 00:09:34 -0500522 entry->proc_fops = &input_devices_fileops;
Dmitry Torokhovf96b4342005-06-30 00:50:29 -0500523
Dmitry Torokhov969b21c2006-04-02 00:09:34 -0500524 entry = create_proc_entry("handlers", 0, proc_bus_input_dir);
Dmitry Torokhovf96b4342005-06-30 00:50:29 -0500525 if (!entry)
526 goto fail2;
527
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 entry->owner = THIS_MODULE;
Dmitry Torokhov969b21c2006-04-02 00:09:34 -0500529 entry->proc_fops = &input_handlers_fileops;
Dmitry Torokhovf96b4342005-06-30 00:50:29 -0500530
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 return 0;
Dmitry Torokhovf96b4342005-06-30 00:50:29 -0500532
533 fail2: remove_proc_entry("devices", proc_bus_input_dir);
534 fail1: remove_proc_entry("input", proc_bus);
535 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536}
Dmitry Torokhovf96b4342005-06-30 00:50:29 -0500537
Andrew Mortonbeffbdc2005-07-01 23:54:30 -0500538static void input_proc_exit(void)
Dmitry Torokhovf96b4342005-06-30 00:50:29 -0500539{
540 remove_proc_entry("devices", proc_bus_input_dir);
541 remove_proc_entry("handlers", proc_bus_input_dir);
542 remove_proc_entry("input", proc_bus);
543}
544
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545#else /* !CONFIG_PROC_FS */
Dmitry Torokhovf96b4342005-06-30 00:50:29 -0500546static inline void input_wakeup_procfs_readers(void) { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547static inline int input_proc_init(void) { return 0; }
Dmitry Torokhovf96b4342005-06-30 00:50:29 -0500548static inline void input_proc_exit(void) { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549#endif
550
Dmitry Torokhov5c1e9a62005-09-15 02:01:55 -0500551#define INPUT_DEV_STRING_ATTR_SHOW(name) \
552static ssize_t input_dev_show_##name(struct class_device *dev, char *buf) \
553{ \
554 struct input_dev *input_dev = to_input_dev(dev); \
555 int retval; \
556 \
Jes Sorensene676c232006-02-19 00:21:46 -0500557 retval = mutex_lock_interruptible(&input_dev->mutex); \
Dmitry Torokhov5c1e9a62005-09-15 02:01:55 -0500558 if (retval) \
559 return retval; \
560 \
Dmitry Torokhov2db66872006-04-02 00:09:26 -0500561 retval = scnprintf(buf, PAGE_SIZE, \
562 "%s\n", input_dev->name ? input_dev->name : ""); \
Dmitry Torokhov5c1e9a62005-09-15 02:01:55 -0500563 \
Jes Sorensene676c232006-02-19 00:21:46 -0500564 mutex_unlock(&input_dev->mutex); \
Dmitry Torokhov5c1e9a62005-09-15 02:01:55 -0500565 \
566 return retval; \
Greg Kroah-Hartman629b77a2005-10-27 22:25:43 -0700567} \
568static CLASS_DEVICE_ATTR(name, S_IRUGO, input_dev_show_##name, NULL);
Dmitry Torokhov5c1e9a62005-09-15 02:01:55 -0500569
570INPUT_DEV_STRING_ATTR_SHOW(name);
571INPUT_DEV_STRING_ATTR_SHOW(phys);
572INPUT_DEV_STRING_ATTR_SHOW(uniq);
573
Kay Sieversbd37e5a2006-01-05 13:19:55 +0100574static int print_modalias_bits(char *buf, int size, char prefix, unsigned long *arr,
Rusty Russell1d8f4302005-12-07 21:40:34 +0100575 unsigned int min, unsigned int max)
576{
577 int len, i;
578
Kay Sieversbd37e5a2006-01-05 13:19:55 +0100579 len = snprintf(buf, size, "%c", prefix);
Rusty Russell1d8f4302005-12-07 21:40:34 +0100580 for (i = min; i < max; i++)
581 if (arr[LONG(i)] & BIT(i))
Kay Sieversbd37e5a2006-01-05 13:19:55 +0100582 len += snprintf(buf + len, size - len, "%X,", i);
583 return len;
584}
585
Dmitry Torokhov2db66872006-04-02 00:09:26 -0500586static int input_print_modalias(char *buf, int size, struct input_dev *id,
587 int add_cr)
Kay Sieversbd37e5a2006-01-05 13:19:55 +0100588{
589 int len;
590
591 len = snprintf(buf, size, "input:b%04Xv%04Xp%04Xe%04X-",
592 id->id.bustype,
593 id->id.vendor,
594 id->id.product,
595 id->id.version);
596
597 len += print_modalias_bits(buf + len, size - len, 'e', id->evbit,
598 0, EV_MAX);
599 len += print_modalias_bits(buf + len, size - len, 'k', id->keybit,
600 KEY_MIN_INTERESTING, KEY_MAX);
601 len += print_modalias_bits(buf + len, size - len, 'r', id->relbit,
602 0, REL_MAX);
603 len += print_modalias_bits(buf + len, size - len, 'a', id->absbit,
604 0, ABS_MAX);
605 len += print_modalias_bits(buf + len, size - len, 'm', id->mscbit,
606 0, MSC_MAX);
607 len += print_modalias_bits(buf + len, size - len, 'l', id->ledbit,
608 0, LED_MAX);
609 len += print_modalias_bits(buf + len, size - len, 's', id->sndbit,
610 0, SND_MAX);
611 len += print_modalias_bits(buf + len, size - len, 'f', id->ffbit,
612 0, FF_MAX);
613 len += print_modalias_bits(buf + len, size - len, 'w', id->swbit,
614 0, SW_MAX);
Dmitry Torokhov2db66872006-04-02 00:09:26 -0500615
616 if (add_cr)
617 len += snprintf(buf + len, size - len, "\n");
618
Rusty Russell1d8f4302005-12-07 21:40:34 +0100619 return len;
620}
621
622static ssize_t input_dev_show_modalias(struct class_device *dev, char *buf)
623{
624 struct input_dev *id = to_input_dev(dev);
Kay Sieversbd37e5a2006-01-05 13:19:55 +0100625 ssize_t len;
Rusty Russell1d8f4302005-12-07 21:40:34 +0100626
Dmitry Torokhov2db66872006-04-02 00:09:26 -0500627 len = input_print_modalias(buf, PAGE_SIZE, id, 1);
628
629 return max_t(int, len, PAGE_SIZE);
Rusty Russell1d8f4302005-12-07 21:40:34 +0100630}
631static CLASS_DEVICE_ATTR(modalias, S_IRUGO, input_dev_show_modalias, NULL);
632
Greg Kroah-Hartman629b77a2005-10-27 22:25:43 -0700633static struct attribute *input_dev_attrs[] = {
634 &class_device_attr_name.attr,
635 &class_device_attr_phys.attr,
636 &class_device_attr_uniq.attr,
Rusty Russell1d8f4302005-12-07 21:40:34 +0100637 &class_device_attr_modalias.attr,
Greg Kroah-Hartman629b77a2005-10-27 22:25:43 -0700638 NULL
639};
640
Dmitry Torokhovbd0ef232005-11-20 00:56:31 -0500641static struct attribute_group input_dev_attr_group = {
Greg Kroah-Hartman629b77a2005-10-27 22:25:43 -0700642 .attrs = input_dev_attrs,
Dmitry Torokhov5c1e9a62005-09-15 02:01:55 -0500643};
644
645#define INPUT_DEV_ID_ATTR(name) \
646static ssize_t input_dev_show_id_##name(struct class_device *dev, char *buf) \
647{ \
648 struct input_dev *input_dev = to_input_dev(dev); \
Dmitry Torokhov2db66872006-04-02 00:09:26 -0500649 return scnprintf(buf, PAGE_SIZE, "%04x\n", input_dev->id.name); \
Dmitry Torokhov5c1e9a62005-09-15 02:01:55 -0500650} \
651static CLASS_DEVICE_ATTR(name, S_IRUGO, input_dev_show_id_##name, NULL);
652
653INPUT_DEV_ID_ATTR(bustype);
654INPUT_DEV_ID_ATTR(vendor);
655INPUT_DEV_ID_ATTR(product);
656INPUT_DEV_ID_ATTR(version);
657
658static struct attribute *input_dev_id_attrs[] = {
659 &class_device_attr_bustype.attr,
660 &class_device_attr_vendor.attr,
661 &class_device_attr_product.attr,
662 &class_device_attr_version.attr,
663 NULL
664};
665
666static struct attribute_group input_dev_id_attr_group = {
667 .name = "id",
668 .attrs = input_dev_id_attrs,
669};
670
Dmitry Torokhov969b21c2006-04-02 00:09:34 -0500671static int input_print_bitmap(char *buf, int buf_size, unsigned long *bitmap,
672 int max, int add_cr)
673{
674 int i;
675 int len = 0;
676
677 for (i = NBITS(max) - 1; i > 0; i--)
678 if (bitmap[i])
679 break;
680
681 for (; i >= 0; i--)
682 len += snprintf(buf + len, max(buf_size - len, 0),
683 "%lx%s", bitmap[i], i > 0 ? " " : "");
684
685 if (add_cr)
686 len += snprintf(buf + len, max(buf_size - len, 0), "\n");
687
688 return len;
689}
690
Dmitry Torokhov5c1e9a62005-09-15 02:01:55 -0500691#define INPUT_DEV_CAP_ATTR(ev, bm) \
692static ssize_t input_dev_show_cap_##bm(struct class_device *dev, char *buf) \
693{ \
694 struct input_dev *input_dev = to_input_dev(dev); \
Dmitry Torokhov2db66872006-04-02 00:09:26 -0500695 int len = input_print_bitmap(buf, PAGE_SIZE, \
696 input_dev->bm##bit, ev##_MAX, 1); \
697 return min_t(int, len, PAGE_SIZE); \
Dmitry Torokhov5c1e9a62005-09-15 02:01:55 -0500698} \
699static CLASS_DEVICE_ATTR(bm, S_IRUGO, input_dev_show_cap_##bm, NULL);
700
701INPUT_DEV_CAP_ATTR(EV, ev);
702INPUT_DEV_CAP_ATTR(KEY, key);
703INPUT_DEV_CAP_ATTR(REL, rel);
704INPUT_DEV_CAP_ATTR(ABS, abs);
705INPUT_DEV_CAP_ATTR(MSC, msc);
706INPUT_DEV_CAP_ATTR(LED, led);
707INPUT_DEV_CAP_ATTR(SND, snd);
708INPUT_DEV_CAP_ATTR(FF, ff);
709INPUT_DEV_CAP_ATTR(SW, sw);
710
711static struct attribute *input_dev_caps_attrs[] = {
712 &class_device_attr_ev.attr,
713 &class_device_attr_key.attr,
714 &class_device_attr_rel.attr,
715 &class_device_attr_abs.attr,
716 &class_device_attr_msc.attr,
717 &class_device_attr_led.attr,
718 &class_device_attr_snd.attr,
719 &class_device_attr_ff.attr,
720 &class_device_attr_sw.attr,
721 NULL
722};
723
724static struct attribute_group input_dev_caps_attr_group = {
725 .name = "capabilities",
726 .attrs = input_dev_caps_attrs,
727};
728
Dmitry Torokhovd19fbe82005-09-15 02:01:39 -0500729static void input_dev_release(struct class_device *class_dev)
730{
731 struct input_dev *dev = to_input_dev(class_dev);
732
733 kfree(dev);
734 module_put(THIS_MODULE);
735}
736
Dmitry Torokhova7fadbe2005-09-15 02:01:57 -0500737/*
Kay Sievers312c0042005-11-16 09:00:00 +0100738 * Input uevent interface - loading event handlers based on
Dmitry Torokhova7fadbe2005-09-15 02:01:57 -0500739 * device bitfields.
740 */
Kay Sievers312c0042005-11-16 09:00:00 +0100741static int input_add_uevent_bm_var(char **envp, int num_envp, int *cur_index,
Dmitry Torokhova7fadbe2005-09-15 02:01:57 -0500742 char *buffer, int buffer_size, int *cur_len,
743 const char *name, unsigned long *bitmap, int max)
744{
745 if (*cur_index >= num_envp - 1)
746 return -ENOMEM;
747
748 envp[*cur_index] = buffer + *cur_len;
749
750 *cur_len += snprintf(buffer + *cur_len, max(buffer_size - *cur_len, 0), name);
751 if (*cur_len > buffer_size)
752 return -ENOMEM;
753
754 *cur_len += input_print_bitmap(buffer + *cur_len,
755 max(buffer_size - *cur_len, 0),
Dmitry Torokhov2db66872006-04-02 00:09:26 -0500756 bitmap, max, 0) + 1;
Dmitry Torokhova7fadbe2005-09-15 02:01:57 -0500757 if (*cur_len > buffer_size)
758 return -ENOMEM;
759
760 (*cur_index)++;
761 return 0;
762}
763
764#define INPUT_ADD_HOTPLUG_VAR(fmt, val...) \
765 do { \
Kay Sievers312c0042005-11-16 09:00:00 +0100766 int err = add_uevent_var(envp, num_envp, &i, \
Dmitry Torokhova7fadbe2005-09-15 02:01:57 -0500767 buffer, buffer_size, &len, \
768 fmt, val); \
769 if (err) \
770 return err; \
771 } while (0)
772
773#define INPUT_ADD_HOTPLUG_BM_VAR(name, bm, max) \
774 do { \
Kay Sievers312c0042005-11-16 09:00:00 +0100775 int err = input_add_uevent_bm_var(envp, num_envp, &i, \
Dmitry Torokhova7fadbe2005-09-15 02:01:57 -0500776 buffer, buffer_size, &len, \
777 name, bm, max); \
778 if (err) \
779 return err; \
780 } while (0)
781
Kay Sievers312c0042005-11-16 09:00:00 +0100782static int input_dev_uevent(struct class_device *cdev, char **envp,
783 int num_envp, char *buffer, int buffer_size)
Dmitry Torokhova7fadbe2005-09-15 02:01:57 -0500784{
785 struct input_dev *dev = to_input_dev(cdev);
786 int i = 0;
787 int len = 0;
788
789 INPUT_ADD_HOTPLUG_VAR("PRODUCT=%x/%x/%x/%x",
790 dev->id.bustype, dev->id.vendor,
791 dev->id.product, dev->id.version);
792 if (dev->name)
793 INPUT_ADD_HOTPLUG_VAR("NAME=\"%s\"", dev->name);
794 if (dev->phys)
795 INPUT_ADD_HOTPLUG_VAR("PHYS=\"%s\"", dev->phys);
Dmitry Torokhov08de1f02005-11-08 21:34:29 -0800796 if (dev->uniq)
Dmitry Torokhova7fadbe2005-09-15 02:01:57 -0500797 INPUT_ADD_HOTPLUG_VAR("UNIQ=\"%s\"", dev->uniq);
798
799 INPUT_ADD_HOTPLUG_BM_VAR("EV=", dev->evbit, EV_MAX);
800 if (test_bit(EV_KEY, dev->evbit))
801 INPUT_ADD_HOTPLUG_BM_VAR("KEY=", dev->keybit, KEY_MAX);
802 if (test_bit(EV_REL, dev->evbit))
803 INPUT_ADD_HOTPLUG_BM_VAR("REL=", dev->relbit, REL_MAX);
804 if (test_bit(EV_ABS, dev->evbit))
805 INPUT_ADD_HOTPLUG_BM_VAR("ABS=", dev->absbit, ABS_MAX);
806 if (test_bit(EV_MSC, dev->evbit))
807 INPUT_ADD_HOTPLUG_BM_VAR("MSC=", dev->mscbit, MSC_MAX);
808 if (test_bit(EV_LED, dev->evbit))
809 INPUT_ADD_HOTPLUG_BM_VAR("LED=", dev->ledbit, LED_MAX);
810 if (test_bit(EV_SND, dev->evbit))
811 INPUT_ADD_HOTPLUG_BM_VAR("SND=", dev->sndbit, SND_MAX);
812 if (test_bit(EV_FF, dev->evbit))
813 INPUT_ADD_HOTPLUG_BM_VAR("FF=", dev->ffbit, FF_MAX);
814 if (test_bit(EV_SW, dev->evbit))
815 INPUT_ADD_HOTPLUG_BM_VAR("SW=", dev->swbit, SW_MAX);
816
Kay Sieversbd37e5a2006-01-05 13:19:55 +0100817 envp[i++] = buffer + len;
818 len += snprintf(buffer + len, buffer_size - len, "MODALIAS=");
Dmitry Torokhov2db66872006-04-02 00:09:26 -0500819 len += input_print_modalias(buffer + len, buffer_size - len, dev, 0) + 1;
Dmitry Torokhova7fadbe2005-09-15 02:01:57 -0500820
Kay Sieversbd37e5a2006-01-05 13:19:55 +0100821 envp[i] = NULL;
Dmitry Torokhova7fadbe2005-09-15 02:01:57 -0500822 return 0;
823}
824
Greg Kroah-Hartmanea9f2402005-10-27 22:25:43 -0700825struct class input_class = {
826 .name = "input",
Dmitry Torokhovd19fbe82005-09-15 02:01:39 -0500827 .release = input_dev_release,
Kay Sievers312c0042005-11-16 09:00:00 +0100828 .uevent = input_dev_uevent,
Dmitry Torokhovd19fbe82005-09-15 02:01:39 -0500829};
830
831struct input_dev *input_allocate_device(void)
832{
833 struct input_dev *dev;
834
835 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
836 if (dev) {
837 dev->dynalloc = 1;
Greg Kroah-Hartmanea9f2402005-10-27 22:25:43 -0700838 dev->cdev.class = &input_class;
Dmitry Torokhovd19fbe82005-09-15 02:01:39 -0500839 class_device_initialize(&dev->cdev);
840 INIT_LIST_HEAD(&dev->h_list);
841 INIT_LIST_HEAD(&dev->node);
842 }
843
844 return dev;
845}
846
Dmitry Torokhov5f945482005-11-02 22:51:46 -0500847int input_register_device(struct input_dev *dev)
Dmitry Torokhovf96b4342005-06-30 00:50:29 -0500848{
Dmitry Torokhovbd0ef232005-11-20 00:56:31 -0500849 static atomic_t input_no = ATOMIC_INIT(0);
Dmitry Torokhovf96b4342005-06-30 00:50:29 -0500850 struct input_handle *handle;
851 struct input_handler *handler;
852 struct input_device_id *id;
Dmitry Torokhovbd0ef232005-11-20 00:56:31 -0500853 const char *path;
854 int error;
Dmitry Torokhovf96b4342005-06-30 00:50:29 -0500855
Dmitry Torokhov5f945482005-11-02 22:51:46 -0500856 if (!dev->dynalloc) {
857 printk(KERN_WARNING "input: device %s is statically allocated, will not register\n"
858 "Please convert to input_allocate_device() or contact dtor_core@ameritech.net\n",
859 dev->name ? dev->name : "<Unknown>");
860 return -EINVAL;
861 }
Dmitry Torokhovf96b4342005-06-30 00:50:29 -0500862
Jes Sorensene676c232006-02-19 00:21:46 -0500863 mutex_init(&dev->mutex);
Dmitry Torokhov5f945482005-11-02 22:51:46 -0500864 set_bit(EV_SYN, dev->evbit);
Dmitry Torokhovf96b4342005-06-30 00:50:29 -0500865
866 /*
867 * If delay and period are pre-set by the driver, then autorepeating
868 * is handled by the driver itself and we don't do it in input.c.
869 */
870
871 init_timer(&dev->timer);
872 if (!dev->rep[REP_DELAY] && !dev->rep[REP_PERIOD]) {
873 dev->timer.data = (long) dev;
874 dev->timer.function = input_repeat_key;
875 dev->rep[REP_DELAY] = 250;
876 dev->rep[REP_PERIOD] = 33;
877 }
878
879 INIT_LIST_HEAD(&dev->h_list);
880 list_add_tail(&dev->node, &input_dev_list);
881
Dmitry Torokhovbd0ef232005-11-20 00:56:31 -0500882 dev->cdev.class = &input_class;
883 snprintf(dev->cdev.class_id, sizeof(dev->cdev.class_id),
884 "input%ld", (unsigned long) atomic_inc_return(&input_no) - 1);
885
886 error = class_device_add(&dev->cdev);
887 if (error)
888 return error;
889
890 error = sysfs_create_group(&dev->cdev.kobj, &input_dev_attr_group);
891 if (error)
892 goto fail1;
893
894 error = sysfs_create_group(&dev->cdev.kobj, &input_dev_id_attr_group);
895 if (error)
896 goto fail2;
897
898 error = sysfs_create_group(&dev->cdev.kobj, &input_dev_caps_attr_group);
899 if (error)
900 goto fail3;
901
902 __module_get(THIS_MODULE);
903
904 path = kobject_get_path(&dev->cdev.kobj, GFP_KERNEL);
905 printk(KERN_INFO "input: %s as %s\n",
906 dev->name ? dev->name : "Unspecified device", path ? path : "N/A");
907 kfree(path);
Greg Kroah-Hartman10204022005-10-27 22:25:43 -0700908
Dmitry Torokhovf96b4342005-06-30 00:50:29 -0500909 list_for_each_entry(handler, &input_handler_list, node)
910 if (!handler->blacklist || !input_match_device(handler->blacklist, dev))
911 if ((id = input_match_device(handler->id_table, dev)))
912 if ((handle = handler->connect(handler, dev, id)))
913 input_link_handle(handle);
914
Dmitry Torokhovf96b4342005-06-30 00:50:29 -0500915 input_wakeup_procfs_readers();
Dmitry Torokhov5f945482005-11-02 22:51:46 -0500916
917 return 0;
Dmitry Torokhovbd0ef232005-11-20 00:56:31 -0500918
919 fail3: sysfs_remove_group(&dev->cdev.kobj, &input_dev_id_attr_group);
920 fail2: sysfs_remove_group(&dev->cdev.kobj, &input_dev_attr_group);
921 fail1: class_device_del(&dev->cdev);
922 return error;
Dmitry Torokhovf96b4342005-06-30 00:50:29 -0500923}
924
925void input_unregister_device(struct input_dev *dev)
926{
927 struct list_head * node, * next;
928
929 if (!dev) return;
930
931 del_timer_sync(&dev->timer);
932
933 list_for_each_safe(node, next, &dev->h_list) {
934 struct input_handle * handle = to_handle(node);
935 list_del_init(&handle->d_node);
936 list_del_init(&handle->h_node);
937 handle->handler->disconnect(handle);
938 }
939
Dmitry Torokhovf96b4342005-06-30 00:50:29 -0500940 list_del_init(&dev->node);
941
Dmitry Torokhov5f945482005-11-02 22:51:46 -0500942 sysfs_remove_group(&dev->cdev.kobj, &input_dev_caps_attr_group);
943 sysfs_remove_group(&dev->cdev.kobj, &input_dev_id_attr_group);
Dmitry Torokhovbd0ef232005-11-20 00:56:31 -0500944 sysfs_remove_group(&dev->cdev.kobj, &input_dev_attr_group);
Dmitry Torokhov5f945482005-11-02 22:51:46 -0500945 class_device_unregister(&dev->cdev);
Dmitry Torokhovd19fbe82005-09-15 02:01:39 -0500946
Dmitry Torokhovf96b4342005-06-30 00:50:29 -0500947 input_wakeup_procfs_readers();
948}
949
950void input_register_handler(struct input_handler *handler)
951{
952 struct input_dev *dev;
953 struct input_handle *handle;
954 struct input_device_id *id;
955
956 if (!handler) return;
957
958 INIT_LIST_HEAD(&handler->h_list);
959
960 if (handler->fops != NULL)
961 input_table[handler->minor >> 5] = handler;
962
963 list_add_tail(&handler->node, &input_handler_list);
964
965 list_for_each_entry(dev, &input_dev_list, node)
966 if (!handler->blacklist || !input_match_device(handler->blacklist, dev))
967 if ((id = input_match_device(handler->id_table, dev)))
968 if ((handle = handler->connect(handler, dev, id)))
969 input_link_handle(handle);
970
971 input_wakeup_procfs_readers();
972}
973
974void input_unregister_handler(struct input_handler *handler)
975{
976 struct list_head * node, * next;
977
978 list_for_each_safe(node, next, &handler->h_list) {
979 struct input_handle * handle = to_handle_h(node);
980 list_del_init(&handle->h_node);
981 list_del_init(&handle->d_node);
982 handler->disconnect(handle);
983 }
984
985 list_del_init(&handler->node);
986
987 if (handler->fops != NULL)
988 input_table[handler->minor >> 5] = NULL;
989
990 input_wakeup_procfs_readers();
991}
992
993static int input_open_file(struct inode *inode, struct file *file)
994{
995 struct input_handler *handler = input_table[iminor(inode) >> 5];
Arjan van de Ven99ac48f2006-03-28 01:56:41 -0800996 const struct file_operations *old_fops, *new_fops = NULL;
Dmitry Torokhovf96b4342005-06-30 00:50:29 -0500997 int err;
998
999 /* No load-on-demand here? */
1000 if (!handler || !(new_fops = fops_get(handler->fops)))
1001 return -ENODEV;
1002
1003 /*
1004 * That's _really_ odd. Usually NULL ->open means "nothing special",
1005 * not "no device". Oh, well...
1006 */
1007 if (!new_fops->open) {
1008 fops_put(new_fops);
1009 return -ENODEV;
1010 }
1011 old_fops = file->f_op;
1012 file->f_op = new_fops;
1013
1014 err = new_fops->open(inode, file);
1015
1016 if (err) {
1017 fops_put(file->f_op);
1018 file->f_op = fops_get(old_fops);
1019 }
1020 fops_put(old_fops);
1021 return err;
1022}
1023
1024static struct file_operations input_fops = {
1025 .owner = THIS_MODULE,
1026 .open = input_open_file,
1027};
1028
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029static int __init input_init(void)
1030{
Dmitry Torokhovf96b4342005-06-30 00:50:29 -05001031 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032
Greg Kroah-Hartmanea9f2402005-10-27 22:25:43 -07001033 err = class_register(&input_class);
Dmitry Torokhovd19fbe82005-09-15 02:01:39 -05001034 if (err) {
1035 printk(KERN_ERR "input: unable to register input_dev class\n");
1036 return err;
1037 }
1038
Dmitry Torokhovf96b4342005-06-30 00:50:29 -05001039 err = input_proc_init();
1040 if (err)
Greg Kroah-Hartmanb0fdfeb2005-10-27 22:25:43 -07001041 goto fail1;
Dmitry Torokhovf96b4342005-06-30 00:50:29 -05001042
1043 err = register_chrdev(INPUT_MAJOR, "input", &input_fops);
1044 if (err) {
1045 printk(KERN_ERR "input: unable to register char major %d", INPUT_MAJOR);
Greg Kroah-Hartmanb0fdfeb2005-10-27 22:25:43 -07001046 goto fail2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 }
Dmitry Torokhovf96b4342005-06-30 00:50:29 -05001048
Dmitry Torokhovf96b4342005-06-30 00:50:29 -05001049 return 0;
1050
Greg Kroah-Hartmanb0fdfeb2005-10-27 22:25:43 -07001051 fail2: input_proc_exit();
Greg Kroah-Hartmanea9f2402005-10-27 22:25:43 -07001052 fail1: class_unregister(&input_class);
Dmitry Torokhovf96b4342005-06-30 00:50:29 -05001053 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054}
1055
1056static void __exit input_exit(void)
1057{
Dmitry Torokhovf96b4342005-06-30 00:50:29 -05001058 input_proc_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 unregister_chrdev(INPUT_MAJOR, "input");
Greg Kroah-Hartmanea9f2402005-10-27 22:25:43 -07001060 class_unregister(&input_class);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061}
1062
1063subsys_initcall(input_init);
1064module_exit(input_exit);