aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@g5.osdl.org>2005-10-28 16:09:47 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2005-10-28 16:09:47 -0400
commit84860bf0644d7c45afe7ddbd30731c3e3c371fae (patch)
treed6c4b98a9c3fd9981e7fcc5d7729c9e01e327767 /drivers/input
parent8caf89157d64f1eedba37113afb4b303b2b3e301 (diff)
parent6fbfddcb52d8d9fa2cd209f5ac2a1c87497d55b5 (diff)
Merge master.kernel.org:/pub/scm/linux/kernel/git/gregkh/driver-2.6
Diffstat (limited to 'drivers/input')
-rw-r--r--drivers/input/evdev.c16
-rw-r--r--drivers/input/input.c445
-rw-r--r--drivers/input/joydev.c16
-rw-r--r--drivers/input/joystick/adi.c93
-rw-r--r--drivers/input/joystick/amijoy.c85
-rw-r--r--drivers/input/joystick/analog.c96
-rw-r--r--drivers/input/joystick/cobra.c66
-rw-r--r--drivers/input/joystick/db9.c292
-rw-r--r--drivers/input/joystick/gamecon.c396
-rw-r--r--drivers/input/joystick/gf2k.c69
-rw-r--r--drivers/input/joystick/grip.c77
-rw-r--r--drivers/input/joystick/grip_mp.c149
-rw-r--r--drivers/input/joystick/guillemot.c51
-rw-r--r--drivers/input/joystick/iforce/iforce-main.c106
-rw-r--r--drivers/input/joystick/iforce/iforce-packets.c5
-rw-r--r--drivers/input/joystick/iforce/iforce-serio.c10
-rw-r--r--drivers/input/joystick/iforce/iforce-usb.c22
-rw-r--r--drivers/input/joystick/iforce/iforce.h2
-rw-r--r--drivers/input/joystick/interact.c53
-rw-r--r--drivers/input/joystick/magellan.c71
-rw-r--r--drivers/input/joystick/sidewinder.c70
-rw-r--r--drivers/input/joystick/spaceball.c82
-rw-r--r--drivers/input/joystick/spaceorb.c78
-rw-r--r--drivers/input/joystick/stinger.c75
-rw-r--r--drivers/input/joystick/tmdc.c324
-rw-r--r--drivers/input/joystick/turbografx.c215
-rw-r--r--drivers/input/joystick/twidjoy.c120
-rw-r--r--drivers/input/joystick/warrior.c83
-rw-r--r--drivers/input/keyboard/amikbd.c59
-rw-r--r--drivers/input/keyboard/atkbd.c188
-rw-r--r--drivers/input/keyboard/corgikbd.c96
-rw-r--r--drivers/input/keyboard/lkkbd.c128
-rw-r--r--drivers/input/keyboard/maple_keyb.c72
-rw-r--r--drivers/input/keyboard/newtonkbd.c83
-rw-r--r--drivers/input/keyboard/spitzkbd.c119
-rw-r--r--drivers/input/keyboard/sunkbd.c117
-rw-r--r--drivers/input/keyboard/xtkbd.c80
-rw-r--r--drivers/input/misc/m68kspkr.c36
-rw-r--r--drivers/input/misc/pcspkr.c30
-rw-r--r--drivers/input/misc/sparcspkr.c47
-rw-r--r--drivers/input/mouse/alps.c63
-rw-r--r--drivers/input/mouse/alps.h2
-rw-r--r--drivers/input/mouse/amimouse.c49
-rw-r--r--drivers/input/mouse/inport.c96
-rw-r--r--drivers/input/mouse/lifebook.c16
-rw-r--r--drivers/input/mouse/logibm.c88
-rw-r--r--drivers/input/mouse/logips2pp.c20
-rw-r--r--drivers/input/mouse/maplemouse.c10
-rw-r--r--drivers/input/mouse/pc110pad.c64
-rw-r--r--drivers/input/mouse/psmouse-base.c99
-rw-r--r--drivers/input/mouse/psmouse.h2
-rw-r--r--drivers/input/mouse/rpcmouse.c43
-rw-r--r--drivers/input/mouse/sermouse.c82
-rw-r--r--drivers/input/mouse/synaptics.c6
-rw-r--r--drivers/input/mouse/vsxxxaa.c84
-rw-r--r--drivers/input/mousedev.c25
-rw-r--r--drivers/input/serio/i8042.c13
-rw-r--r--drivers/input/touchscreen/corgi_ts.c127
-rw-r--r--drivers/input/touchscreen/elo.c89
-rw-r--r--drivers/input/touchscreen/gunze.c66
-rw-r--r--drivers/input/touchscreen/h3600_ts_input.c149
-rw-r--r--drivers/input/touchscreen/hp680_ts_input.c50
-rw-r--r--drivers/input/touchscreen/mk712.c80
-rw-r--r--drivers/input/touchscreen/mtouch.c64
-rw-r--r--drivers/input/tsdev.c19
65 files changed, 2984 insertions, 2644 deletions
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index 3738d173f9a6..a4696cd0978c 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -20,7 +20,6 @@
20#include <linux/major.h> 20#include <linux/major.h>
21#include <linux/smp_lock.h> 21#include <linux/smp_lock.h>
22#include <linux/device.h> 22#include <linux/device.h>
23#include <linux/devfs_fs_kernel.h>
24#include <linux/compat.h> 23#include <linux/compat.h>
25 24
26struct evdev { 25struct evdev {
@@ -662,6 +661,7 @@ static struct file_operations evdev_fops = {
662static struct input_handle *evdev_connect(struct input_handler *handler, struct input_dev *dev, struct input_device_id *id) 661static struct input_handle *evdev_connect(struct input_handler *handler, struct input_dev *dev, struct input_device_id *id)
663{ 662{
664 struct evdev *evdev; 663 struct evdev *evdev;
664 struct class_device *cdev;
665 int minor; 665 int minor;
666 666
667 for (minor = 0; minor < EVDEV_MINORS && evdev_table[minor]; minor++); 667 for (minor = 0; minor < EVDEV_MINORS && evdev_table[minor]; minor++);
@@ -687,11 +687,13 @@ static struct input_handle *evdev_connect(struct input_handler *handler, struct
687 687
688 evdev_table[minor] = evdev; 688 evdev_table[minor] = evdev;
689 689
690 devfs_mk_cdev(MKDEV(INPUT_MAJOR, EVDEV_MINOR_BASE + minor), 690 cdev = class_device_create(&input_class, &dev->cdev,
691 S_IFCHR|S_IRUGO|S_IWUSR, "input/event%d", minor);
692 class_device_create(input_class,
693 MKDEV(INPUT_MAJOR, EVDEV_MINOR_BASE + minor), 691 MKDEV(INPUT_MAJOR, EVDEV_MINOR_BASE + minor),
694 dev->dev, "event%d", minor); 692 dev->cdev.dev, evdev->name);
693
694 /* temporary symlink to keep userspace happy */
695 sysfs_create_link(&input_class.subsys.kset.kobj, &cdev->kobj,
696 evdev->name);
695 697
696 return &evdev->handle; 698 return &evdev->handle;
697} 699}
@@ -701,9 +703,9 @@ static void evdev_disconnect(struct input_handle *handle)
701 struct evdev *evdev = handle->private; 703 struct evdev *evdev = handle->private;
702 struct evdev_list *list; 704 struct evdev_list *list;
703 705
704 class_device_destroy(input_class, 706 sysfs_remove_link(&input_class.subsys.kset.kobj, evdev->name);
707 class_device_destroy(&input_class,
705 MKDEV(INPUT_MAJOR, EVDEV_MINOR_BASE + evdev->minor)); 708 MKDEV(INPUT_MAJOR, EVDEV_MINOR_BASE + evdev->minor));
706 devfs_remove("input/event%d", evdev->minor);
707 evdev->exist = 0; 709 evdev->exist = 0;
708 710
709 if (evdev->open) { 711 if (evdev->open) {
diff --git a/drivers/input/input.c b/drivers/input/input.c
index 14ae5583e198..3b1685ff9d10 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -22,12 +22,12 @@
22#include <linux/interrupt.h> 22#include <linux/interrupt.h>
23#include <linux/poll.h> 23#include <linux/poll.h>
24#include <linux/device.h> 24#include <linux/device.h>
25#include <linux/devfs_fs_kernel.h>
26 25
27MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>"); 26MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>");
28MODULE_DESCRIPTION("Input core"); 27MODULE_DESCRIPTION("Input core");
29MODULE_LICENSE("GPL"); 28MODULE_LICENSE("GPL");
30 29
30EXPORT_SYMBOL(input_allocate_device);
31EXPORT_SYMBOL(input_register_device); 31EXPORT_SYMBOL(input_register_device);
32EXPORT_SYMBOL(input_unregister_device); 32EXPORT_SYMBOL(input_unregister_device);
33EXPORT_SYMBOL(input_register_handler); 33EXPORT_SYMBOL(input_register_handler);
@@ -39,7 +39,7 @@ EXPORT_SYMBOL(input_close_device);
39EXPORT_SYMBOL(input_accept_process); 39EXPORT_SYMBOL(input_accept_process);
40EXPORT_SYMBOL(input_flush_device); 40EXPORT_SYMBOL(input_flush_device);
41EXPORT_SYMBOL(input_event); 41EXPORT_SYMBOL(input_event);
42EXPORT_SYMBOL(input_class); 42EXPORT_SYMBOL_GPL(input_class);
43 43
44#define INPUT_DEVICES 256 44#define INPUT_DEVICES 256
45 45
@@ -316,124 +316,21 @@ static struct input_device_id *input_match_device(struct input_device_id *id, st
316 return NULL; 316 return NULL;
317} 317}
318 318
319 319static int input_print_bitmap(char *buf, int buf_size, unsigned long *bitmap, int max)
320/*
321 * Input hotplugging interface - loading event handlers based on
322 * device bitfields.
323 */
324
325#ifdef CONFIG_HOTPLUG
326
327/*
328 * Input hotplugging invokes what /proc/sys/kernel/hotplug says
329 * (normally /sbin/hotplug) when input devices get added or removed.
330 *
331 * This invokes a user mode policy agent, typically helping to load driver
332 * or other modules, configure the device, and more. Drivers can provide
333 * a MODULE_DEVICE_TABLE to help with module loading subtasks.
334 *
335 */
336
337#define SPRINTF_BIT_A(bit, name, max) \
338 do { \
339 envp[i++] = scratch; \
340 scratch += sprintf(scratch, name); \
341 for (j = NBITS(max) - 1; j >= 0; j--) \
342 if (dev->bit[j]) break; \
343 for (; j >= 0; j--) \
344 scratch += sprintf(scratch, "%lx ", dev->bit[j]); \
345 scratch++; \
346 } while (0)
347
348#define SPRINTF_BIT_A2(bit, name, max, ev) \
349 do { \
350 if (test_bit(ev, dev->evbit)) \
351 SPRINTF_BIT_A(bit, name, max); \
352 } while (0)
353
354static void input_call_hotplug(char *verb, struct input_dev *dev)
355{ 320{
356 char *argv[3], **envp, *buf, *scratch; 321 int i;
357 int i = 0, j, value; 322 int len = 0;
358
359 if (!hotplug_path[0]) {
360 printk(KERN_ERR "input.c: calling hotplug without a hotplug agent defined\n");
361 return;
362 }
363 if (in_interrupt()) {
364 printk(KERN_ERR "input.c: calling hotplug from interrupt\n");
365 return;
366 }
367 if (!current->fs->root) {
368 printk(KERN_WARNING "input.c: calling hotplug without valid filesystem\n");
369 return;
370 }
371 if (!(envp = (char **) kmalloc(20 * sizeof(char *), GFP_KERNEL))) {
372 printk(KERN_ERR "input.c: not enough memory allocating hotplug environment\n");
373 return;
374 }
375 if (!(buf = kmalloc(1024, GFP_KERNEL))) {
376 kfree (envp);
377 printk(KERN_ERR "input.c: not enough memory allocating hotplug environment\n");
378 return;
379 }
380
381 argv[0] = hotplug_path;
382 argv[1] = "input";
383 argv[2] = NULL;
384
385 envp[i++] = "HOME=/";
386 envp[i++] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
387
388 scratch = buf;
389
390 envp[i++] = scratch;
391 scratch += sprintf(scratch, "ACTION=%s", verb) + 1;
392
393 envp[i++] = scratch;
394 scratch += sprintf(scratch, "PRODUCT=%x/%x/%x/%x",
395 dev->id.bustype, dev->id.vendor, dev->id.product, dev->id.version) + 1;
396
397 if (dev->name) {
398 envp[i++] = scratch;
399 scratch += sprintf(scratch, "NAME=%s", dev->name) + 1;
400 }
401
402 if (dev->phys) {
403 envp[i++] = scratch;
404 scratch += sprintf(scratch, "PHYS=%s", dev->phys) + 1;
405 }
406
407 SPRINTF_BIT_A(evbit, "EV=", EV_MAX);
408 SPRINTF_BIT_A2(keybit, "KEY=", KEY_MAX, EV_KEY);
409 SPRINTF_BIT_A2(relbit, "REL=", REL_MAX, EV_REL);
410 SPRINTF_BIT_A2(absbit, "ABS=", ABS_MAX, EV_ABS);
411 SPRINTF_BIT_A2(mscbit, "MSC=", MSC_MAX, EV_MSC);
412 SPRINTF_BIT_A2(ledbit, "LED=", LED_MAX, EV_LED);
413 SPRINTF_BIT_A2(sndbit, "SND=", SND_MAX, EV_SND);
414 SPRINTF_BIT_A2(ffbit, "FF=", FF_MAX, EV_FF);
415 SPRINTF_BIT_A2(swbit, "SW=", SW_MAX, EV_SW);
416
417 envp[i++] = NULL;
418
419#ifdef INPUT_DEBUG
420 printk(KERN_DEBUG "input.c: calling %s %s [%s %s %s %s %s]\n",
421 argv[0], argv[1], envp[0], envp[1], envp[2], envp[3], envp[4]);
422#endif
423
424 value = call_usermodehelper(argv [0], argv, envp, 0);
425 323
426 kfree(buf); 324 for (i = NBITS(max) - 1; i > 0; i--)
427 kfree(envp); 325 if (bitmap[i])
326 break;
428 327
429#ifdef INPUT_DEBUG 328 for (; i >= 0; i--)
430 if (value != 0) 329 len += snprintf(buf + len, max(buf_size - len, 0),
431 printk(KERN_DEBUG "input.c: hotplug returned %d\n", value); 330 "%lx%s", bitmap[i], i > 0 ? " " : "");
432#endif 331 return len;
433} 332}
434 333
435#endif
436
437#ifdef CONFIG_PROC_FS 334#ifdef CONFIG_PROC_FS
438 335
439static struct proc_dir_entry *proc_bus_input_dir; 336static struct proc_dir_entry *proc_bus_input_dir;
@@ -455,37 +352,39 @@ static unsigned int input_devices_poll(struct file *file, poll_table *wait)
455 return 0; 352 return 0;
456} 353}
457 354
458#define SPRINTF_BIT_B(bit, name, max) \ 355#define SPRINTF_BIT(ev, bm) \
459 do { \ 356 do { \
460 len += sprintf(buf + len, "B: %s", name); \ 357 len += sprintf(buf + len, "B: %s=", #ev); \
461 for (i = NBITS(max) - 1; i >= 0; i--) \ 358 len += input_print_bitmap(buf + len, INT_MAX, \
462 if (dev->bit[i]) break; \ 359 dev->bm##bit, ev##_MAX); \
463 for (; i >= 0; i--) \ 360 len += sprintf(buf + len, "\n"); \
464 len += sprintf(buf + len, "%lx ", dev->bit[i]); \
465 len += sprintf(buf + len, "\n"); \
466 } while (0) 361 } while (0)
467 362
468#define SPRINTF_BIT_B2(bit, name, max, ev) \ 363#define TEST_AND_SPRINTF_BIT(ev, bm) \
469 do { \ 364 do { \
470 if (test_bit(ev, dev->evbit)) \ 365 if (test_bit(EV_##ev, dev->evbit)) \
471 SPRINTF_BIT_B(bit, name, max); \ 366 SPRINTF_BIT(ev, bm); \
472 } while (0) 367 } while (0)
473 368
474static int input_devices_read(char *buf, char **start, off_t pos, int count, int *eof, void *data) 369static int input_devices_read(char *buf, char **start, off_t pos, int count, int *eof, void *data)
475{ 370{
476 struct input_dev *dev; 371 struct input_dev *dev;
477 struct input_handle *handle; 372 struct input_handle *handle;
373 const char *path;
478 374
479 off_t at = 0; 375 off_t at = 0;
480 int i, len, cnt = 0; 376 int len, cnt = 0;
481 377
482 list_for_each_entry(dev, &input_dev_list, node) { 378 list_for_each_entry(dev, &input_dev_list, node) {
483 379
380 path = dev->dynalloc ? kobject_get_path(&dev->cdev.kobj, GFP_KERNEL) : NULL;
381
484 len = sprintf(buf, "I: Bus=%04x Vendor=%04x Product=%04x Version=%04x\n", 382 len = sprintf(buf, "I: Bus=%04x Vendor=%04x Product=%04x Version=%04x\n",
485 dev->id.bustype, dev->id.vendor, dev->id.product, dev->id.version); 383 dev->id.bustype, dev->id.vendor, dev->id.product, dev->id.version);
486 384
487 len += sprintf(buf + len, "N: Name=\"%s\"\n", dev->name ? dev->name : ""); 385 len += sprintf(buf + len, "N: Name=\"%s\"\n", dev->name ? dev->name : "");
488 len += sprintf(buf + len, "P: Phys=%s\n", dev->phys ? dev->phys : ""); 386 len += sprintf(buf + len, "P: Phys=%s\n", dev->phys ? dev->phys : "");
387 len += sprintf(buf + len, "S: Sysfs=%s\n", path ? path : "");
489 len += sprintf(buf + len, "H: Handlers="); 388 len += sprintf(buf + len, "H: Handlers=");
490 389
491 list_for_each_entry(handle, &dev->h_list, d_node) 390 list_for_each_entry(handle, &dev->h_list, d_node)
@@ -493,15 +392,15 @@ static int input_devices_read(char *buf, char **start, off_t pos, int count, int
493 392
494 len += sprintf(buf + len, "\n"); 393 len += sprintf(buf + len, "\n");
495 394
496 SPRINTF_BIT_B(evbit, "EV=", EV_MAX); 395 SPRINTF_BIT(EV, ev);
497 SPRINTF_BIT_B2(keybit, "KEY=", KEY_MAX, EV_KEY); 396 TEST_AND_SPRINTF_BIT(KEY, key);
498 SPRINTF_BIT_B2(relbit, "REL=", REL_MAX, EV_REL); 397 TEST_AND_SPRINTF_BIT(REL, rel);
499 SPRINTF_BIT_B2(absbit, "ABS=", ABS_MAX, EV_ABS); 398 TEST_AND_SPRINTF_BIT(ABS, abs);
500 SPRINTF_BIT_B2(mscbit, "MSC=", MSC_MAX, EV_MSC); 399 TEST_AND_SPRINTF_BIT(MSC, msc);
501 SPRINTF_BIT_B2(ledbit, "LED=", LED_MAX, EV_LED); 400 TEST_AND_SPRINTF_BIT(LED, led);
502 SPRINTF_BIT_B2(sndbit, "SND=", SND_MAX, EV_SND); 401 TEST_AND_SPRINTF_BIT(SND, snd);
503 SPRINTF_BIT_B2(ffbit, "FF=", FF_MAX, EV_FF); 402 TEST_AND_SPRINTF_BIT(FF, ff);
504 SPRINTF_BIT_B2(swbit, "SW=", SW_MAX, EV_SW); 403 TEST_AND_SPRINTF_BIT(SW, sw);
505 404
506 len += sprintf(buf + len, "\n"); 405 len += sprintf(buf + len, "\n");
507 406
@@ -516,6 +415,8 @@ static int input_devices_read(char *buf, char **start, off_t pos, int count, int
516 if (cnt >= count) 415 if (cnt >= count)
517 break; 416 break;
518 } 417 }
418
419 kfree(path);
519 } 420 }
520 421
521 if (&dev->node == &input_dev_list) 422 if (&dev->node == &input_dev_list)
@@ -606,6 +507,240 @@ static inline int input_proc_init(void) { return 0; }
606static inline void input_proc_exit(void) { } 507static inline void input_proc_exit(void) { }
607#endif 508#endif
608 509
510#define INPUT_DEV_STRING_ATTR_SHOW(name) \
511static ssize_t input_dev_show_##name(struct class_device *dev, char *buf) \
512{ \
513 struct input_dev *input_dev = to_input_dev(dev); \
514 int retval; \
515 \
516 retval = down_interruptible(&input_dev->sem); \
517 if (retval) \
518 return retval; \
519 \
520 retval = sprintf(buf, "%s\n", input_dev->name ? input_dev->name : ""); \
521 \
522 up(&input_dev->sem); \
523 \
524 return retval; \
525} \
526static CLASS_DEVICE_ATTR(name, S_IRUGO, input_dev_show_##name, NULL);
527
528INPUT_DEV_STRING_ATTR_SHOW(name);
529INPUT_DEV_STRING_ATTR_SHOW(phys);
530INPUT_DEV_STRING_ATTR_SHOW(uniq);
531
532static struct attribute *input_dev_attrs[] = {
533 &class_device_attr_name.attr,
534 &class_device_attr_phys.attr,
535 &class_device_attr_uniq.attr,
536 NULL
537};
538
539static struct attribute_group input_dev_group = {
540 .attrs = input_dev_attrs,
541};
542
543#define INPUT_DEV_ID_ATTR(name) \
544static ssize_t input_dev_show_id_##name(struct class_device *dev, char *buf) \
545{ \
546 struct input_dev *input_dev = to_input_dev(dev); \
547 return sprintf(buf, "%04x\n", input_dev->id.name); \
548} \
549static CLASS_DEVICE_ATTR(name, S_IRUGO, input_dev_show_id_##name, NULL);
550
551INPUT_DEV_ID_ATTR(bustype);
552INPUT_DEV_ID_ATTR(vendor);
553INPUT_DEV_ID_ATTR(product);
554INPUT_DEV_ID_ATTR(version);
555
556static struct attribute *input_dev_id_attrs[] = {
557 &class_device_attr_bustype.attr,
558 &class_device_attr_vendor.attr,
559 &class_device_attr_product.attr,
560 &class_device_attr_version.attr,
561 NULL
562};
563
564static struct attribute_group input_dev_id_attr_group = {
565 .name = "id",
566 .attrs = input_dev_id_attrs,
567};
568
569#define INPUT_DEV_CAP_ATTR(ev, bm) \
570static ssize_t input_dev_show_cap_##bm(struct class_device *dev, char *buf) \
571{ \
572 struct input_dev *input_dev = to_input_dev(dev); \
573 return input_print_bitmap(buf, PAGE_SIZE, input_dev->bm##bit, ev##_MAX);\
574} \
575static CLASS_DEVICE_ATTR(bm, S_IRUGO, input_dev_show_cap_##bm, NULL);
576
577INPUT_DEV_CAP_ATTR(EV, ev);
578INPUT_DEV_CAP_ATTR(KEY, key);
579INPUT_DEV_CAP_ATTR(REL, rel);
580INPUT_DEV_CAP_ATTR(ABS, abs);
581INPUT_DEV_CAP_ATTR(MSC, msc);
582INPUT_DEV_CAP_ATTR(LED, led);
583INPUT_DEV_CAP_ATTR(SND, snd);
584INPUT_DEV_CAP_ATTR(FF, ff);
585INPUT_DEV_CAP_ATTR(SW, sw);
586
587static struct attribute *input_dev_caps_attrs[] = {
588 &class_device_attr_ev.attr,
589 &class_device_attr_key.attr,
590 &class_device_attr_rel.attr,
591 &class_device_attr_abs.attr,
592 &class_device_attr_msc.attr,
593 &class_device_attr_led.attr,
594 &class_device_attr_snd.attr,
595 &class_device_attr_ff.attr,
596 &class_device_attr_sw.attr,
597 NULL
598};
599
600static struct attribute_group input_dev_caps_attr_group = {
601 .name = "capabilities",
602 .attrs = input_dev_caps_attrs,
603};
604
605static void input_dev_release(struct class_device *class_dev)
606{
607 struct input_dev *dev = to_input_dev(class_dev);
608
609 kfree(dev);
610 module_put(THIS_MODULE);
611}
612
613/*
614 * Input hotplugging interface - loading event handlers based on
615 * device bitfields.
616 */
617static int input_add_hotplug_bm_var(char **envp, int num_envp, int *cur_index,
618 char *buffer, int buffer_size, int *cur_len,
619 const char *name, unsigned long *bitmap, int max)
620{
621 if (*cur_index >= num_envp - 1)
622 return -ENOMEM;
623
624 envp[*cur_index] = buffer + *cur_len;
625
626 *cur_len += snprintf(buffer + *cur_len, max(buffer_size - *cur_len, 0), name);
627 if (*cur_len > buffer_size)
628 return -ENOMEM;
629
630 *cur_len += input_print_bitmap(buffer + *cur_len,
631 max(buffer_size - *cur_len, 0),
632 bitmap, max) + 1;
633 if (*cur_len > buffer_size)
634 return -ENOMEM;
635
636 (*cur_index)++;
637 return 0;
638}
639
640#define INPUT_ADD_HOTPLUG_VAR(fmt, val...) \
641 do { \
642 int err = add_hotplug_env_var(envp, num_envp, &i, \
643 buffer, buffer_size, &len, \
644 fmt, val); \
645 if (err) \
646 return err; \
647 } while (0)
648
649#define INPUT_ADD_HOTPLUG_BM_VAR(name, bm, max) \
650 do { \
651 int err = input_add_hotplug_bm_var(envp, num_envp, &i, \
652 buffer, buffer_size, &len, \
653 name, bm, max); \
654 if (err) \
655 return err; \
656 } while (0)
657
658static int input_dev_hotplug(struct class_device *cdev, char **envp,
659 int num_envp, char *buffer, int buffer_size)
660{
661 struct input_dev *dev = to_input_dev(cdev);
662 int i = 0;
663 int len = 0;
664
665 INPUT_ADD_HOTPLUG_VAR("PRODUCT=%x/%x/%x/%x",
666 dev->id.bustype, dev->id.vendor,
667 dev->id.product, dev->id.version);
668 if (dev->name)
669 INPUT_ADD_HOTPLUG_VAR("NAME=\"%s\"", dev->name);
670 if (dev->phys)
671 INPUT_ADD_HOTPLUG_VAR("PHYS=\"%s\"", dev->phys);
672 if (dev->phys)
673 INPUT_ADD_HOTPLUG_VAR("UNIQ=\"%s\"", dev->uniq);
674
675 INPUT_ADD_HOTPLUG_BM_VAR("EV=", dev->evbit, EV_MAX);
676 if (test_bit(EV_KEY, dev->evbit))
677 INPUT_ADD_HOTPLUG_BM_VAR("KEY=", dev->keybit, KEY_MAX);
678 if (test_bit(EV_REL, dev->evbit))
679 INPUT_ADD_HOTPLUG_BM_VAR("REL=", dev->relbit, REL_MAX);
680 if (test_bit(EV_ABS, dev->evbit))
681 INPUT_ADD_HOTPLUG_BM_VAR("ABS=", dev->absbit, ABS_MAX);
682 if (test_bit(EV_MSC, dev->evbit))
683 INPUT_ADD_HOTPLUG_BM_VAR("MSC=", dev->mscbit, MSC_MAX);
684 if (test_bit(EV_LED, dev->evbit))
685 INPUT_ADD_HOTPLUG_BM_VAR("LED=", dev->ledbit, LED_MAX);
686 if (test_bit(EV_SND, dev->evbit))
687 INPUT_ADD_HOTPLUG_BM_VAR("SND=", dev->sndbit, SND_MAX);
688 if (test_bit(EV_FF, dev->evbit))
689 INPUT_ADD_HOTPLUG_BM_VAR("FF=", dev->ffbit, FF_MAX);
690 if (test_bit(EV_SW, dev->evbit))
691 INPUT_ADD_HOTPLUG_BM_VAR("SW=", dev->swbit, SW_MAX);
692
693 envp[i] = NULL;
694
695 return 0;
696}
697
698struct class input_class = {
699 .name = "input",
700 .release = input_dev_release,
701 .hotplug = input_dev_hotplug,
702};
703
704struct input_dev *input_allocate_device(void)
705{
706 struct input_dev *dev;
707
708 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
709 if (dev) {
710 dev->dynalloc = 1;
711 dev->cdev.class = &input_class;
712 class_device_initialize(&dev->cdev);
713 INIT_LIST_HEAD(&dev->h_list);
714 INIT_LIST_HEAD(&dev->node);
715 }
716
717 return dev;
718}
719
720static void input_register_classdevice(struct input_dev *dev)
721{
722 static atomic_t input_no = ATOMIC_INIT(0);
723 const char *path;
724
725 __module_get(THIS_MODULE);
726
727 dev->dev = dev->cdev.dev;
728
729 snprintf(dev->cdev.class_id, sizeof(dev->cdev.class_id),
730 "input%ld", (unsigned long) atomic_inc_return(&input_no) - 1);
731
732 path = kobject_get_path(&dev->cdev.class->subsys.kset.kobj, GFP_KERNEL);
733 printk(KERN_INFO "input: %s/%s as %s\n",
734 dev->name ? dev->name : "Unspecified device",
735 path ? path : "", dev->cdev.class_id);
736 kfree(path);
737
738 class_device_add(&dev->cdev);
739 sysfs_create_group(&dev->cdev.kobj, &input_dev_group);
740 sysfs_create_group(&dev->cdev.kobj, &input_dev_id_attr_group);
741 sysfs_create_group(&dev->cdev.kobj, &input_dev_caps_attr_group);
742}
743
609void input_register_device(struct input_dev *dev) 744void input_register_device(struct input_dev *dev)
610{ 745{
611 struct input_handle *handle; 746 struct input_handle *handle;
@@ -632,15 +767,15 @@ void input_register_device(struct input_dev *dev)
632 INIT_LIST_HEAD(&dev->h_list); 767 INIT_LIST_HEAD(&dev->h_list);
633 list_add_tail(&dev->node, &input_dev_list); 768 list_add_tail(&dev->node, &input_dev_list);
634 769
770 if (dev->dynalloc)
771 input_register_classdevice(dev);
772
635 list_for_each_entry(handler, &input_handler_list, node) 773 list_for_each_entry(handler, &input_handler_list, node)
636 if (!handler->blacklist || !input_match_device(handler->blacklist, dev)) 774 if (!handler->blacklist || !input_match_device(handler->blacklist, dev))
637 if ((id = input_match_device(handler->id_table, dev))) 775 if ((id = input_match_device(handler->id_table, dev)))
638 if ((handle = handler->connect(handler, dev, id))) 776 if ((handle = handler->connect(handler, dev, id)))
639 input_link_handle(handle); 777 input_link_handle(handle);
640 778
641#ifdef CONFIG_HOTPLUG
642 input_call_hotplug("add", dev);
643#endif
644 779
645 input_wakeup_procfs_readers(); 780 input_wakeup_procfs_readers();
646} 781}
@@ -660,12 +795,14 @@ void input_unregister_device(struct input_dev *dev)
660 handle->handler->disconnect(handle); 795 handle->handler->disconnect(handle);
661 } 796 }
662 797
663#ifdef CONFIG_HOTPLUG
664 input_call_hotplug("remove", dev);
665#endif
666
667 list_del_init(&dev->node); 798 list_del_init(&dev->node);
668 799
800 if (dev->dynalloc) {
801 sysfs_remove_group(&dev->cdev.kobj, &input_dev_caps_attr_group);
802 sysfs_remove_group(&dev->cdev.kobj, &input_dev_id_attr_group);
803 class_device_unregister(&dev->cdev);
804 }
805
669 input_wakeup_procfs_readers(); 806 input_wakeup_procfs_readers();
670} 807}
671 808
@@ -748,16 +885,14 @@ static struct file_operations input_fops = {
748 .open = input_open_file, 885 .open = input_open_file,
749}; 886};
750 887
751struct class *input_class;
752
753static int __init input_init(void) 888static int __init input_init(void)
754{ 889{
755 int err; 890 int err;
756 891
757 input_class = class_create(THIS_MODULE, "input"); 892 err = class_register(&input_class);
758 if (IS_ERR(input_class)) { 893 if (err) {
759 printk(KERN_ERR "input: unable to register input class\n"); 894 printk(KERN_ERR "input: unable to register input_dev class\n");
760 return PTR_ERR(input_class); 895 return err;
761 } 896 }
762 897
763 err = input_proc_init(); 898 err = input_proc_init();
@@ -770,24 +905,18 @@ static int __init input_init(void)
770 goto fail2; 905 goto fail2;
771 } 906 }
772 907
773 err = devfs_mk_dir("input");
774 if (err)
775 goto fail3;
776
777 return 0; 908 return 0;
778 909
779 fail3: unregister_chrdev(INPUT_MAJOR, "input");
780 fail2: input_proc_exit(); 910 fail2: input_proc_exit();
781 fail1: class_destroy(input_class); 911 fail1: class_unregister(&input_class);
782 return err; 912 return err;
783} 913}
784 914
785static void __exit input_exit(void) 915static void __exit input_exit(void)
786{ 916{
787 input_proc_exit(); 917 input_proc_exit();
788 devfs_remove("input");
789 unregister_chrdev(INPUT_MAJOR, "input"); 918 unregister_chrdev(INPUT_MAJOR, "input");
790 class_destroy(input_class); 919 class_unregister(&input_class);
791} 920}
792 921
793subsys_initcall(input_init); 922subsys_initcall(input_init);
diff --git a/drivers/input/joydev.c b/drivers/input/joydev.c
index e0938d1d3ad7..20e2972b9204 100644
--- a/drivers/input/joydev.c
+++ b/drivers/input/joydev.c
@@ -26,7 +26,6 @@
26#include <linux/init.h> 26#include <linux/init.h>
27#include <linux/smp_lock.h> 27#include <linux/smp_lock.h>
28#include <linux/device.h> 28#include <linux/device.h>
29#include <linux/devfs_fs_kernel.h>
30 29
31MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); 30MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
32MODULE_DESCRIPTION("Joystick device interfaces"); 31MODULE_DESCRIPTION("Joystick device interfaces");
@@ -449,6 +448,7 @@ static struct file_operations joydev_fops = {
449static struct input_handle *joydev_connect(struct input_handler *handler, struct input_dev *dev, struct input_device_id *id) 448static struct input_handle *joydev_connect(struct input_handler *handler, struct input_dev *dev, struct input_device_id *id)
450{ 449{
451 struct joydev *joydev; 450 struct joydev *joydev;
451 struct class_device *cdev;
452 int i, j, t, minor; 452 int i, j, t, minor;
453 453
454 for (minor = 0; minor < JOYDEV_MINORS && joydev_table[minor]; minor++); 454 for (minor = 0; minor < JOYDEV_MINORS && joydev_table[minor]; minor++);
@@ -514,11 +514,13 @@ static struct input_handle *joydev_connect(struct input_handler *handler, struct
514 514
515 joydev_table[minor] = joydev; 515 joydev_table[minor] = joydev;
516 516
517 devfs_mk_cdev(MKDEV(INPUT_MAJOR, JOYDEV_MINOR_BASE + minor), 517 cdev = class_device_create(&input_class, &dev->cdev,
518 S_IFCHR|S_IRUGO|S_IWUSR, "input/js%d", minor);
519 class_device_create(input_class,
520 MKDEV(INPUT_MAJOR, JOYDEV_MINOR_BASE + minor), 518 MKDEV(INPUT_MAJOR, JOYDEV_MINOR_BASE + minor),
521 dev->dev, "js%d", minor); 519 dev->cdev.dev, joydev->name);
520
521 /* temporary symlink to keep userspace happy */
522 sysfs_create_link(&input_class.subsys.kset.kobj, &cdev->kobj,
523 joydev->name);
522 524
523 return &joydev->handle; 525 return &joydev->handle;
524} 526}
@@ -528,8 +530,8 @@ static void joydev_disconnect(struct input_handle *handle)
528 struct joydev *joydev = handle->private; 530 struct joydev *joydev = handle->private;
529 struct joydev_list *list; 531 struct joydev_list *list;
530 532
531 class_device_destroy(input_class, MKDEV(INPUT_MAJOR, JOYDEV_MINOR_BASE + joydev->minor)); 533 sysfs_remove_link(&input_class.subsys.kset.kobj, joydev->name);
532 devfs_remove("input/js%d", joydev->minor); 534 class_device_destroy(&input_class, MKDEV(INPUT_MAJOR, JOYDEV_MINOR_BASE + joydev->minor));
533 joydev->exist = 0; 535 joydev->exist = 0;
534 536
535 if (joydev->open) { 537 if (joydev->open) {
diff --git a/drivers/input/joystick/adi.c b/drivers/input/joystick/adi.c
index cf35ae638a0d..9d95459f4bcb 100644
--- a/drivers/input/joystick/adi.c
+++ b/drivers/input/joystick/adi.c
@@ -54,7 +54,7 @@ MODULE_LICENSE("GPL");
54#define ADI_MIN_LENGTH 8 54#define ADI_MIN_LENGTH 8
55#define ADI_MIN_LEN_LENGTH 10 55#define ADI_MIN_LEN_LENGTH 10
56#define ADI_MIN_ID_LENGTH 66 56#define ADI_MIN_ID_LENGTH 66
57#define ADI_MAX_NAME_LENGTH 48 57#define ADI_MAX_NAME_LENGTH 64
58#define ADI_MAX_CNAME_LENGTH 16 58#define ADI_MAX_CNAME_LENGTH 16
59#define ADI_MAX_PHYS_LENGTH 64 59#define ADI_MAX_PHYS_LENGTH 64
60 60
@@ -106,7 +106,7 @@ static struct {
106 */ 106 */
107 107
108struct adi { 108struct adi {
109 struct input_dev dev; 109 struct input_dev *dev;
110 int length; 110 int length;
111 int ret; 111 int ret;
112 int idx; 112 int idx;
@@ -215,7 +215,7 @@ static inline int adi_get_bits(struct adi *adi, int count)
215 215
216static int adi_decode(struct adi *adi) 216static int adi_decode(struct adi *adi)
217{ 217{
218 struct input_dev *dev = &adi->dev; 218 struct input_dev *dev = adi->dev;
219 char *abs = adi->abs; 219 char *abs = adi->abs;
220 short *key = adi->key; 220 short *key = adi->key;
221 int i, t; 221 int i, t;
@@ -318,7 +318,8 @@ static void adi_init_digital(struct gameport *gameport)
318 318
319 for (i = 0; seq[i]; i++) { 319 for (i = 0; seq[i]; i++) {
320 gameport_trigger(gameport); 320 gameport_trigger(gameport);
321 if (seq[i] > 0) msleep(seq[i]); 321 if (seq[i] > 0)
322 msleep(seq[i]);
322 if (seq[i] < 0) { 323 if (seq[i] < 0) {
323 mdelay(-seq[i]); 324 mdelay(-seq[i]);
324 udelay(-seq[i]*14); /* It looks like mdelay() is off by approx 1.4% */ 325 udelay(-seq[i]*14); /* It looks like mdelay() is off by approx 1.4% */
@@ -397,42 +398,46 @@ static void adi_id_decode(struct adi *adi, struct adi_port *port)
397 } 398 }
398} 399}
399 400
400static void adi_init_input(struct adi *adi, struct adi_port *port, int half) 401static int adi_init_input(struct adi *adi, struct adi_port *port, int half)
401{ 402{
402 int i, t; 403 struct input_dev *input_dev;
403 char buf[ADI_MAX_NAME_LENGTH]; 404 char buf[ADI_MAX_NAME_LENGTH];
405 int i, t;
404 406
405 if (!adi->length) return; 407 adi->dev = input_dev = input_allocate_device();
406 408 if (!input_dev)
407 init_input_dev(&adi->dev); 409 return -ENOMEM;
408 410
409 t = adi->id < ADI_ID_MAX ? adi->id : ADI_ID_MAX; 411 t = adi->id < ADI_ID_MAX ? adi->id : ADI_ID_MAX;
410 412
411 snprintf(buf, ADI_MAX_PHYS_LENGTH, adi_names[t], adi->id); 413 snprintf(buf, ADI_MAX_PHYS_LENGTH, adi_names[t], adi->id);
412 snprintf(adi->name, ADI_MAX_NAME_LENGTH, "Logitech %s", buf); 414 snprintf(adi->name, ADI_MAX_NAME_LENGTH, "Logitech %s [%s]", buf, adi->cname);
413 snprintf(adi->phys, ADI_MAX_PHYS_LENGTH, "%s/input%d", port->gameport->phys, half); 415 snprintf(adi->phys, ADI_MAX_PHYS_LENGTH, "%s/input%d", port->gameport->phys, half);
414 416
415 adi->abs = adi_abs[t]; 417 adi->abs = adi_abs[t];
416 adi->key = adi_key[t]; 418 adi->key = adi_key[t];
417 419
418 adi->dev.open = adi_open; 420 input_dev->name = adi->name;
419 adi->dev.close = adi_close; 421 input_dev->phys = adi->phys;
422 input_dev->id.bustype = BUS_GAMEPORT;
423 input_dev->id.vendor = GAMEPORT_ID_VENDOR_LOGITECH;
424 input_dev->id.product = adi->id;
425 input_dev->id.version = 0x0100;
426 input_dev->cdev.dev = &port->gameport->dev;
427 input_dev->private = port;
420 428
421 adi->dev.name = adi->name; 429 input_dev->open = adi_open;
422 adi->dev.phys = adi->phys; 430 input_dev->close = adi_close;
423 adi->dev.id.bustype = BUS_GAMEPORT;
424 adi->dev.id.vendor = GAMEPORT_ID_VENDOR_LOGITECH;
425 adi->dev.id.product = adi->id;
426 adi->dev.id.version = 0x0100;
427 431
428 adi->dev.private = port; 432 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
429 adi->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
430 433
431 for (i = 0; i < adi->axes10 + adi->axes8 + (adi->hats + (adi->pad != -1)) * 2; i++) 434 for (i = 0; i < adi->axes10 + adi->axes8 + (adi->hats + (adi->pad != -1)) * 2; i++)
432 set_bit(adi->abs[i], adi->dev.absbit); 435 set_bit(adi->abs[i], input_dev->absbit);
433 436
434 for (i = 0; i < adi->buttons; i++) 437 for (i = 0; i < adi->buttons; i++)
435 set_bit(adi->key[i], adi->dev.keybit); 438 set_bit(adi->key[i], input_dev->keybit);
439
440 return 0;
436} 441}
437 442
438static void adi_init_center(struct adi *adi) 443static void adi_init_center(struct adi *adi)
@@ -445,17 +450,17 @@ static void adi_init_center(struct adi *adi)
445 for (i = 0; i < adi->axes10 + adi->axes8 + (adi->hats + (adi->pad != -1)) * 2; i++) { 450 for (i = 0; i < adi->axes10 + adi->axes8 + (adi->hats + (adi->pad != -1)) * 2; i++) {
446 451
447 t = adi->abs[i]; 452 t = adi->abs[i];
448 x = adi->dev.abs[t]; 453 x = adi->dev->abs[t];
449 454
450 if (t == ABS_THROTTLE || t == ABS_RUDDER || adi->id == ADI_ID_WGPE) 455 if (t == ABS_THROTTLE || t == ABS_RUDDER || adi->id == ADI_ID_WGPE)
451 x = i < adi->axes10 ? 512 : 128; 456 x = i < adi->axes10 ? 512 : 128;
452 457
453 if (i < adi->axes10) 458 if (i < adi->axes10)
454 input_set_abs_params(&adi->dev, t, 64, x * 2 - 64, 2, 16); 459 input_set_abs_params(adi->dev, t, 64, x * 2 - 64, 2, 16);
455 else if (i < adi->axes10 + adi->axes8) 460 else if (i < adi->axes10 + adi->axes8)
456 input_set_abs_params(&adi->dev, t, 48, x * 2 - 48, 1, 16); 461 input_set_abs_params(adi->dev, t, 48, x * 2 - 48, 1, 16);
457 else 462 else
458 input_set_abs_params(&adi->dev, t, -1, 1, 0, 0); 463 input_set_abs_params(adi->dev, t, -1, 1, 0, 0);
459 } 464 }
460} 465}
461 466
@@ -469,7 +474,8 @@ static int adi_connect(struct gameport *gameport, struct gameport_driver *drv)
469 int i; 474 int i;
470 int err; 475 int err;
471 476
472 if (!(port = kzalloc(sizeof(struct adi_port), GFP_KERNEL))) 477 port = kzalloc(sizeof(struct adi_port), GFP_KERNEL);
478 if (!port)
473 return -ENOMEM; 479 return -ENOMEM;
474 480
475 port->gameport = gameport; 481 port->gameport = gameport;
@@ -477,10 +483,8 @@ static int adi_connect(struct gameport *gameport, struct gameport_driver *drv)
477 gameport_set_drvdata(gameport, port); 483 gameport_set_drvdata(gameport, port);
478 484
479 err = gameport_open(gameport, drv, GAMEPORT_MODE_RAW); 485 err = gameport_open(gameport, drv, GAMEPORT_MODE_RAW);
480 if (err) { 486 if (err)
481 kfree(port); 487 goto fail1;
482 return err;
483 }
484 488
485 adi_init_digital(gameport); 489 adi_init_digital(gameport);
486 adi_read_packet(port); 490 adi_read_packet(port);
@@ -490,13 +494,18 @@ static int adi_connect(struct gameport *gameport, struct gameport_driver *drv)
490 494
491 for (i = 0; i < 2; i++) { 495 for (i = 0; i < 2; i++) {
492 adi_id_decode(port->adi + i, port); 496 adi_id_decode(port->adi + i, port);
493 adi_init_input(port->adi + i, port, i); 497
498 if (!port->adi[i].length)
499 continue;
500
501 err = adi_init_input(port->adi + i, port, i);
502 if (err)
503 goto fail2;
494 } 504 }
495 505
496 if (!port->adi[0].length && !port->adi[1].length) { 506 if (!port->adi[0].length && !port->adi[1].length) {
497 gameport_close(gameport); 507 err = -ENODEV;
498 kfree(port); 508 goto fail2;
499 return -ENODEV;
500 } 509 }
501 510
502 gameport_set_poll_handler(gameport, adi_poll); 511 gameport_set_poll_handler(gameport, adi_poll);
@@ -511,12 +520,18 @@ static int adi_connect(struct gameport *gameport, struct gameport_driver *drv)
511 for (i = 0; i < 2; i++) 520 for (i = 0; i < 2; i++)
512 if (port->adi[i].length > 0) { 521 if (port->adi[i].length > 0) {
513 adi_init_center(port->adi + i); 522 adi_init_center(port->adi + i);
514 input_register_device(&port->adi[i].dev); 523 input_register_device(port->adi[i].dev);
515 printk(KERN_INFO "input: %s [%s] on %s\n",
516 port->adi[i].name, port->adi[i].cname, gameport->phys);
517 } 524 }
518 525
519 return 0; 526 return 0;
527
528 fail2: for (i = 0; i < 2; i++)
529 if (port->adi[i].dev)
530 input_free_device(port->adi[i].dev);
531 gameport_close(gameport);
532 fail1: gameport_set_drvdata(gameport, NULL);
533 kfree(port);
534 return err;
520} 535}
521 536
522static void adi_disconnect(struct gameport *gameport) 537static void adi_disconnect(struct gameport *gameport)
@@ -526,7 +541,7 @@ static void adi_disconnect(struct gameport *gameport)
526 541
527 for (i = 0; i < 2; i++) 542 for (i = 0; i < 2; i++)
528 if (port->adi[i].length > 0) 543 if (port->adi[i].length > 0)
529 input_unregister_device(&port->adi[i].dev); 544 input_unregister_device(port->adi[i].dev);
530 gameport_close(gameport); 545 gameport_close(gameport);
531 gameport_set_drvdata(gameport, NULL); 546 gameport_set_drvdata(gameport, NULL);
532 kfree(port); 547 kfree(port);
diff --git a/drivers/input/joystick/amijoy.c b/drivers/input/joystick/amijoy.c
index e996183c5b06..8558a99f6635 100644
--- a/drivers/input/joystick/amijoy.c
+++ b/drivers/input/joystick/amijoy.c
@@ -53,11 +53,9 @@ __obsolete_setup("amijoy=");
53 53
54static int amijoy_used; 54static int amijoy_used;
55static DECLARE_MUTEX(amijoy_sem); 55static DECLARE_MUTEX(amijoy_sem);
56static struct input_dev amijoy_dev[2]; 56static struct input_dev *amijoy_dev[2];
57static char *amijoy_phys[2] = { "amijoy/input0", "amijoy/input1" }; 57static char *amijoy_phys[2] = { "amijoy/input0", "amijoy/input1" };
58 58
59static char *amijoy_name = "Amiga joystick";
60
61static irqreturn_t amijoy_interrupt(int irq, void *dummy, struct pt_regs *fp) 59static irqreturn_t amijoy_interrupt(int irq, void *dummy, struct pt_regs *fp)
62{ 60{
63 int i, data = 0, button = 0; 61 int i, data = 0, button = 0;
@@ -70,15 +68,15 @@ static irqreturn_t amijoy_interrupt(int irq, void *dummy, struct pt_regs *fp)
70 case 1: data = ~custom.joy1dat; button = (~ciaa.pra >> 7) & 1; break; 68 case 1: data = ~custom.joy1dat; button = (~ciaa.pra >> 7) & 1; break;
71 } 69 }
72 70
73 input_regs(amijoy_dev + i, fp); 71 input_regs(amijoy_dev[i], fp);
74 72
75 input_report_key(amijoy_dev + i, BTN_TRIGGER, button); 73 input_report_key(amijoy_dev[i], BTN_TRIGGER, button);
76 74
77 input_report_abs(amijoy_dev + i, ABS_X, ((data >> 1) & 1) - ((data >> 9) & 1)); 75 input_report_abs(amijoy_dev[i], ABS_X, ((data >> 1) & 1) - ((data >> 9) & 1));
78 data = ~(data ^ (data << 1)); 76 data = ~(data ^ (data << 1));
79 input_report_abs(amijoy_dev + i, ABS_Y, ((data >> 1) & 1) - ((data >> 9) & 1)); 77 input_report_abs(amijoy_dev[i], ABS_Y, ((data >> 1) & 1) - ((data >> 9) & 1));
80 78
81 input_sync(amijoy_dev + i); 79 input_sync(amijoy_dev[i]);
82 } 80 }
83 return IRQ_HANDLED; 81 return IRQ_HANDLED;
84} 82}
@@ -114,39 +112,52 @@ static void amijoy_close(struct input_dev *dev)
114static int __init amijoy_init(void) 112static int __init amijoy_init(void)
115{ 113{
116 int i, j; 114 int i, j;
115 int err;
117 116
118 for (i = 0; i < 2; i++) 117 for (i = 0; i < 2; i++) {
119 if (amijoy[i]) { 118 if (!amijoy[i])
120 if (!request_mem_region(CUSTOM_PHYSADDR+10+i*2, 2, 119 continue;
121 "amijoy [Denise]")) {
122 if (i == 1 && amijoy[0]) {
123 input_unregister_device(amijoy_dev);
124 release_mem_region(CUSTOM_PHYSADDR+10, 2);
125 }
126 return -EBUSY;
127 }
128 120
129 amijoy_dev[i].open = amijoy_open; 121 amijoy_dev[i] = input_allocate_device();
130 amijoy_dev[i].close = amijoy_close; 122 if (!amijoy_dev[i]) {
131 amijoy_dev[i].evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 123 err = -ENOMEM;
132 amijoy_dev[i].absbit[0] = BIT(ABS_X) | BIT(ABS_Y); 124 goto fail;
133 amijoy_dev[i].keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT); 125 }
134 for (j = 0; j < 2; j++) {
135 amijoy_dev[i].absmin[ABS_X + j] = -1;
136 amijoy_dev[i].absmax[ABS_X + j] = 1;
137 }
138 126
139 amijoy_dev[i].name = amijoy_name; 127 if (!request_mem_region(CUSTOM_PHYSADDR + 10 + i * 2, 2, "amijoy [Denise]")) {
140 amijoy_dev[i].phys = amijoy_phys[i]; 128 input_free_device(amijoy_dev[i]);
141 amijoy_dev[i].id.bustype = BUS_AMIGA; 129 err = -EBUSY;
142 amijoy_dev[i].id.vendor = 0x0001; 130 goto fail;
143 amijoy_dev[i].id.product = 0x0003; 131 }
144 amijoy_dev[i].id.version = 0x0100;
145 132
146 input_register_device(amijoy_dev + i); 133 amijoy_dev[i]->name = "Amiga joystick";
147 printk(KERN_INFO "input: %s at joy%ddat\n", amijoy_name, i); 134 amijoy_dev[i]->phys = amijoy_phys[i];
135 amijoy_dev[i]->id.bustype = BUS_AMIGA;
136 amijoy_dev[i]->id.vendor = 0x0001;
137 amijoy_dev[i]->id.product = 0x0003;
138 amijoy_dev[i]->id.version = 0x0100;
139
140 amijoy_dev[i]->open = amijoy_open;
141 amijoy_dev[i]->close = amijoy_close;
142
143 amijoy_dev[i]->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
144 amijoy_dev[i]->absbit[0] = BIT(ABS_X) | BIT(ABS_Y);
145 amijoy_dev[i]->keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
146 for (j = 0; j < 2; j++) {
147 amijoy_dev[i]->absmin[ABS_X + j] = -1;
148 amijoy_dev[i]->absmax[ABS_X + j] = 1;
148 } 149 }
150
151 input_register_device(amijoy_dev[i]);
152 }
149 return 0; 153 return 0;
154
155 fail: while (--i >= 0)
156 if (amijoy[i]) {
157 input_unregister_device(amijoy_dev[i]);
158 release_mem_region(CUSTOM_PHYSADDR + 10 + i * 2, 2);
159 }
160 return err;
150} 161}
151 162
152static void __exit amijoy_exit(void) 163static void __exit amijoy_exit(void)
@@ -155,8 +166,8 @@ static void __exit amijoy_exit(void)
155 166
156 for (i = 0; i < 2; i++) 167 for (i = 0; i < 2; i++)
157 if (amijoy[i]) { 168 if (amijoy[i]) {
158 input_unregister_device(amijoy_dev + i); 169 input_unregister_device(amijoy_dev[i]);
159 release_mem_region(CUSTOM_PHYSADDR+10+i*2, 2); 170 release_mem_region(CUSTOM_PHYSADDR + 10 + i * 2, 2);
160 } 171 }
161} 172}
162 173
diff --git a/drivers/input/joystick/analog.c b/drivers/input/joystick/analog.c
index 64b1313a3c66..c75ac6eb1ffb 100644
--- a/drivers/input/joystick/analog.c
+++ b/drivers/input/joystick/analog.c
@@ -111,7 +111,7 @@ static short analog_joy_btn[] = { BTN_TRIGGER, BTN_THUMB, BTN_TOP, BTN_TOP2, BTN
111static unsigned char analog_chf[] = { 0xf, 0x0, 0x1, 0x9, 0x2, 0x4, 0xc, 0x8, 0x3, 0x5, 0xb, 0x7, 0xd, 0xe, 0xa, 0x6 }; 111static unsigned char analog_chf[] = { 0xf, 0x0, 0x1, 0x9, 0x2, 0x4, 0xc, 0x8, 0x3, 0x5, 0xb, 0x7, 0xd, 0xe, 0xa, 0x6 };
112 112
113struct analog { 113struct analog {
114 struct input_dev dev; 114 struct input_dev *dev;
115 int mask; 115 int mask;
116 short *buttons; 116 short *buttons;
117 char name[ANALOG_MAX_NAME_LENGTH]; 117 char name[ANALOG_MAX_NAME_LENGTH];
@@ -182,7 +182,7 @@ static unsigned long analog_faketime = 0;
182 182
183static void analog_decode(struct analog *analog, int *axes, int *initial, int buttons) 183static void analog_decode(struct analog *analog, int *axes, int *initial, int buttons)
184{ 184{
185 struct input_dev *dev = &analog->dev; 185 struct input_dev *dev = analog->dev;
186 int i, j; 186 int i, j;
187 187
188 if (analog->mask & ANALOG_HAT_FCS) 188 if (analog->mask & ANALOG_HAT_FCS)
@@ -428,27 +428,30 @@ static void analog_name(struct analog *analog)
428 * analog_init_device() 428 * analog_init_device()
429 */ 429 */
430 430
431static void analog_init_device(struct analog_port *port, struct analog *analog, int index) 431static int analog_init_device(struct analog_port *port, struct analog *analog, int index)
432{ 432{
433 struct input_dev *input_dev;
433 int i, j, t, v, w, x, y, z; 434 int i, j, t, v, w, x, y, z;
434 435
435 analog_name(analog); 436 analog_name(analog);
436 sprintf(analog->phys, "%s/input%d", port->gameport->phys, index); 437 sprintf(analog->phys, "%s/input%d", port->gameport->phys, index);
437 analog->buttons = (analog->mask & ANALOG_GAMEPAD) ? analog_pad_btn : analog_joy_btn; 438 analog->buttons = (analog->mask & ANALOG_GAMEPAD) ? analog_pad_btn : analog_joy_btn;
438 439
439 init_input_dev(&analog->dev); 440 analog->dev = input_dev = input_allocate_device();
441 if (!input_dev)
442 return -ENOMEM;
440 443
441 analog->dev.name = analog->name; 444 input_dev->name = analog->name;
442 analog->dev.phys = analog->phys; 445 input_dev->phys = analog->phys;
443 analog->dev.id.bustype = BUS_GAMEPORT; 446 input_dev->id.bustype = BUS_GAMEPORT;
444 analog->dev.id.vendor = GAMEPORT_ID_VENDOR_ANALOG; 447 input_dev->id.vendor = GAMEPORT_ID_VENDOR_ANALOG;
445 analog->dev.id.product = analog->mask >> 4; 448 input_dev->id.product = analog->mask >> 4;
446 analog->dev.id.version = 0x0100; 449 input_dev->id.version = 0x0100;
447 450
448 analog->dev.open = analog_open; 451 input_dev->open = analog_open;
449 analog->dev.close = analog_close; 452 input_dev->close = analog_close;
450 analog->dev.private = port; 453 input_dev->private = port;
451 analog->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 454 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
452 455
453 for (i = j = 0; i < 4; i++) 456 for (i = j = 0; i < 4; i++)
454 if (analog->mask & (1 << i)) { 457 if (analog->mask & (1 << i)) {
@@ -461,8 +464,6 @@ static void analog_init_device(struct analog_port *port, struct analog *analog,
461 v = (x >> 3); 464 v = (x >> 3);
462 w = (x >> 3); 465 w = (x >> 3);
463 466
464 set_bit(t, analog->dev.absbit);
465
466 if ((i == 2 || i == 3) && (j == 2 || j == 3) && (z > (y >> 3))) 467 if ((i == 2 || i == 3) && (j == 2 || j == 3) && (z > (y >> 3)))
467 x = y; 468 x = y;
468 469
@@ -472,11 +473,7 @@ static void analog_init_device(struct analog_port *port, struct analog *analog,
472 w = (x >> 4); 473 w = (x >> 4);
473 } 474 }
474 475
475 analog->dev.absmax[t] = (x << 1) - v; 476 input_set_abs_params(input_dev, t, v, (x << 1) - v, port->fuzz, w);
476 analog->dev.absmin[t] = v;
477 analog->dev.absfuzz[t] = port->fuzz;
478 analog->dev.absflat[t] = w;
479
480 j++; 477 j++;
481 } 478 }
482 479
@@ -484,41 +481,30 @@ static void analog_init_device(struct analog_port *port, struct analog *analog,
484 if (analog->mask & analog_exts[i]) 481 if (analog->mask & analog_exts[i])
485 for (x = 0; x < 2; x++) { 482 for (x = 0; x < 2; x++) {
486 t = analog_hats[j++]; 483 t = analog_hats[j++];
487 set_bit(t, analog->dev.absbit); 484 input_set_abs_params(input_dev, t, -1, 1, 0, 0);
488 analog->dev.absmax[t] = 1;
489 analog->dev.absmin[t] = -1;
490 } 485 }
491 486
492 for (i = j = 0; i < 4; i++) 487 for (i = j = 0; i < 4; i++)
493 if (analog->mask & (0x10 << i)) 488 if (analog->mask & (0x10 << i))
494 set_bit(analog->buttons[j++], analog->dev.keybit); 489 set_bit(analog->buttons[j++], input_dev->keybit);
495 490
496 if (analog->mask & ANALOG_BTNS_CHF) 491 if (analog->mask & ANALOG_BTNS_CHF)
497 for (i = 0; i < 2; i++) 492 for (i = 0; i < 2; i++)
498 set_bit(analog->buttons[j++], analog->dev.keybit); 493 set_bit(analog->buttons[j++], input_dev->keybit);
499 494
500 if (analog->mask & ANALOG_HBTN_CHF) 495 if (analog->mask & ANALOG_HBTN_CHF)
501 for (i = 0; i < 4; i++) 496 for (i = 0; i < 4; i++)
502 set_bit(analog->buttons[j++], analog->dev.keybit); 497 set_bit(analog->buttons[j++], input_dev->keybit);
503 498
504 for (i = 0; i < 4; i++) 499 for (i = 0; i < 4; i++)
505 if (analog->mask & (ANALOG_BTN_TL << i)) 500 if (analog->mask & (ANALOG_BTN_TL << i))
506 set_bit(analog_pads[i], analog->dev.keybit); 501 set_bit(analog_pads[i], input_dev->keybit);
507 502
508 analog_decode(analog, port->axes, port->initial, port->buttons); 503 analog_decode(analog, port->axes, port->initial, port->buttons);
509 504
510 input_register_device(&analog->dev); 505 input_register_device(analog->dev);
511 506
512 printk(KERN_INFO "input: %s at %s", analog->name, port->gameport->phys); 507 return 0;
513
514 if (port->cooked)
515 printk(" [ADC port]\n");
516 else
517 printk(" [%s timer, %d %sHz clock, %d ns res]\n", TIME_NAME,
518 port->speed > 10000 ? (port->speed + 800) / 1000 : port->speed,
519 port->speed > 10000 ? "M" : "k",
520 port->speed > 10000 ? (port->loop * 1000) / (port->speed / 1000)
521 : (port->loop * 1000000) / port->speed);
522} 508}
523 509
524/* 510/*
@@ -659,37 +645,41 @@ static int analog_connect(struct gameport *gameport, struct gameport_driver *drv
659 return - ENOMEM; 645 return - ENOMEM;
660 646
661 err = analog_init_port(gameport, drv, port); 647 err = analog_init_port(gameport, drv, port);
662 if (err) { 648 if (err)
663 kfree(port); 649 goto fail1;
664 return err;
665 }
666 650
667 err = analog_init_masks(port); 651 err = analog_init_masks(port);
668 if (err) { 652 if (err)
669 gameport_close(gameport); 653 goto fail2;
670 gameport_set_drvdata(gameport, NULL);
671 kfree(port);
672 return err;
673 }
674 654
675 gameport_set_poll_handler(gameport, analog_poll); 655 gameport_set_poll_handler(gameport, analog_poll);
676 gameport_set_poll_interval(gameport, 10); 656 gameport_set_poll_interval(gameport, 10);
677 657
678 for (i = 0; i < 2; i++) 658 for (i = 0; i < 2; i++)
679 if (port->analog[i].mask) 659 if (port->analog[i].mask) {
680 analog_init_device(port, port->analog + i, i); 660 err = analog_init_device(port, port->analog + i, i);
661 if (err)
662 goto fail3;
663 }
681 664
682 return 0; 665 return 0;
666
667 fail3: while (--i >= 0)
668 input_unregister_device(port->analog[i].dev);
669 fail2: gameport_close(gameport);
670 fail1: gameport_set_drvdata(gameport, NULL);
671 kfree(port);
672 return err;
683} 673}
684 674
685static void analog_disconnect(struct gameport *gameport) 675static void analog_disconnect(struct gameport *gameport)
686{ 676{
687 int i;
688 struct analog_port *port = gameport_get_drvdata(gameport); 677 struct analog_port *port = gameport_get_drvdata(gameport);
678 int i;
689 679
690 for (i = 0; i < 2; i++) 680 for (i = 0; i < 2; i++)
691 if (port->analog[i].mask) 681 if (port->analog[i].mask)
692 input_unregister_device(&port->analog[i].dev); 682 input_unregister_device(port->analog[i].dev);
693 gameport_close(gameport); 683 gameport_close(gameport);
694 gameport_set_drvdata(gameport, NULL); 684 gameport_set_drvdata(gameport, NULL);
695 printk(KERN_INFO "analog.c: %d out of %d reads (%d%%) on %s failed\n", 685 printk(KERN_INFO "analog.c: %d out of %d reads (%d%%) on %s failed\n",
diff --git a/drivers/input/joystick/cobra.c b/drivers/input/joystick/cobra.c
index 0b2e9fa26579..9a3dfc724a41 100644
--- a/drivers/input/joystick/cobra.c
+++ b/drivers/input/joystick/cobra.c
@@ -44,13 +44,11 @@ MODULE_LICENSE("GPL");
44#define COBRA_MAX_STROBE 45 /* 45 us max wait for first strobe */ 44#define COBRA_MAX_STROBE 45 /* 45 us max wait for first strobe */
45#define COBRA_LENGTH 36 45#define COBRA_LENGTH 36
46 46
47static char* cobra_name = "Creative Labs Blaster GamePad Cobra";
48
49static int cobra_btn[] = { BTN_START, BTN_SELECT, BTN_TL, BTN_TR, BTN_X, BTN_Y, BTN_Z, BTN_A, BTN_B, BTN_C, BTN_TL2, BTN_TR2, 0 }; 47static int cobra_btn[] = { BTN_START, BTN_SELECT, BTN_TL, BTN_TR, BTN_X, BTN_Y, BTN_Z, BTN_A, BTN_B, BTN_C, BTN_TL2, BTN_TR2, 0 };
50 48
51struct cobra { 49struct cobra {
52 struct gameport *gameport; 50 struct gameport *gameport;
53 struct input_dev dev[2]; 51 struct input_dev *dev[2];
54 int reads; 52 int reads;
55 int bads; 53 int bads;
56 unsigned char exists; 54 unsigned char exists;
@@ -128,7 +126,7 @@ static void cobra_poll(struct gameport *gameport)
128 for (i = 0; i < 2; i++) 126 for (i = 0; i < 2; i++)
129 if (cobra->exists & r & (1 << i)) { 127 if (cobra->exists & r & (1 << i)) {
130 128
131 dev = cobra->dev + i; 129 dev = cobra->dev[i];
132 130
133 input_report_abs(dev, ABS_X, ((data[i] >> 4) & 1) - ((data[i] >> 3) & 1)); 131 input_report_abs(dev, ABS_X, ((data[i] >> 4) & 1) - ((data[i] >> 3) & 1));
134 input_report_abs(dev, ABS_Y, ((data[i] >> 2) & 1) - ((data[i] >> 1) & 1)); 132 input_report_abs(dev, ABS_Y, ((data[i] >> 2) & 1) - ((data[i] >> 1) & 1));
@@ -159,11 +157,13 @@ static void cobra_close(struct input_dev *dev)
159static int cobra_connect(struct gameport *gameport, struct gameport_driver *drv) 157static int cobra_connect(struct gameport *gameport, struct gameport_driver *drv)
160{ 158{
161 struct cobra *cobra; 159 struct cobra *cobra;
160 struct input_dev *input_dev;
162 unsigned int data[2]; 161 unsigned int data[2];
163 int i, j; 162 int i, j;
164 int err; 163 int err;
165 164
166 if (!(cobra = kzalloc(sizeof(struct cobra), GFP_KERNEL))) 165 cobra = kzalloc(sizeof(struct cobra), GFP_KERNEL);
166 if (!cobra)
167 return -ENOMEM; 167 return -ENOMEM;
168 168
169 cobra->gameport = gameport; 169 cobra->gameport = gameport;
@@ -191,38 +191,46 @@ static int cobra_connect(struct gameport *gameport, struct gameport_driver *drv)
191 gameport_set_poll_handler(gameport, cobra_poll); 191 gameport_set_poll_handler(gameport, cobra_poll);
192 gameport_set_poll_interval(gameport, 20); 192 gameport_set_poll_interval(gameport, 20);
193 193
194 for (i = 0; i < 2; i++) 194 for (i = 0; i < 2; i++) {
195 if ((cobra->exists >> i) & 1) { 195 if (~(cobra->exists >> i) & 1)
196 196 continue;
197 sprintf(cobra->phys[i], "%s/input%d", gameport->phys, i);
198 197
199 cobra->dev[i].private = cobra; 198 cobra->dev[i] = input_dev = input_allocate_device();
200 cobra->dev[i].open = cobra_open; 199 if (!input_dev) {
201 cobra->dev[i].close = cobra_close; 200 err = -ENOMEM;
201 goto fail3;
202 }
202 203
203 cobra->dev[i].name = cobra_name; 204 sprintf(cobra->phys[i], "%s/input%d", gameport->phys, i);
204 cobra->dev[i].phys = cobra->phys[i];
205 cobra->dev[i].id.bustype = BUS_GAMEPORT;
206 cobra->dev[i].id.vendor = GAMEPORT_ID_VENDOR_CREATIVE;
207 cobra->dev[i].id.product = 0x0008;
208 cobra->dev[i].id.version = 0x0100;
209 205
210 cobra->dev[i].evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 206 input_dev->name = "Creative Labs Blaster GamePad Cobra";
207 input_dev->phys = cobra->phys[i];
208 input_dev->id.bustype = BUS_GAMEPORT;
209 input_dev->id.vendor = GAMEPORT_ID_VENDOR_CREATIVE;
210 input_dev->id.product = 0x0008;
211 input_dev->id.version = 0x0100;
212 input_dev->cdev.dev = &gameport->dev;
213 input_dev->private = cobra;
211 214
212 input_set_abs_params(&cobra->dev[i], ABS_X, -1, 1, 0, 0); 215 input_dev->open = cobra_open;
213 input_set_abs_params(&cobra->dev[i], ABS_Y, -1, 1, 0, 0); 216 input_dev->close = cobra_close;
214 217
215 for (j = 0; cobra_btn[j]; j++) 218 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
216 set_bit(cobra_btn[j], cobra->dev[i].keybit); 219 input_set_abs_params(input_dev, ABS_X, -1, 1, 0, 0);
220 input_set_abs_params(input_dev, ABS_Y, -1, 1, 0, 0);
221 for (j = 0; cobra_btn[j]; j++)
222 set_bit(cobra_btn[j], input_dev->keybit);
217 223
218 input_register_device(&cobra->dev[i]); 224 input_register_device(cobra->dev[i]);
219 printk(KERN_INFO "input: %s on %s\n", cobra_name, gameport->phys); 225 }
220 }
221 226
222 return 0; 227 return 0;
223 228
224fail2: gameport_close(gameport); 229 fail3: for (i = 0; i < 2; i++)
225fail1: gameport_set_drvdata(gameport, NULL); 230 if (cobra->dev[i])
231 input_unregister_device(cobra->dev[i]);
232 fail2: gameport_close(gameport);
233 fail1: gameport_set_drvdata(gameport, NULL);
226 kfree(cobra); 234 kfree(cobra);
227 return err; 235 return err;
228} 236}
@@ -234,7 +242,7 @@ static void cobra_disconnect(struct gameport *gameport)
234 242
235 for (i = 0; i < 2; i++) 243 for (i = 0; i < 2; i++)
236 if ((cobra->exists >> i) & 1) 244 if ((cobra->exists >> i) & 1)
237 input_unregister_device(cobra->dev + i); 245 input_unregister_device(cobra->dev[i]);
238 gameport_close(gameport); 246 gameport_close(gameport);
239 gameport_set_drvdata(gameport, NULL); 247 gameport_set_drvdata(gameport, NULL);
240 kfree(cobra); 248 kfree(cobra);
diff --git a/drivers/input/joystick/db9.c b/drivers/input/joystick/db9.c
index 2a3e4bb2da50..499344c72756 100644
--- a/drivers/input/joystick/db9.c
+++ b/drivers/input/joystick/db9.c
@@ -43,25 +43,28 @@ MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
43MODULE_DESCRIPTION("Atari, Amstrad, Commodore, Amiga, Sega, etc. joystick driver"); 43MODULE_DESCRIPTION("Atari, Amstrad, Commodore, Amiga, Sega, etc. joystick driver");
44MODULE_LICENSE("GPL"); 44MODULE_LICENSE("GPL");
45 45
46static int db9[] __initdata = { -1, 0 }; 46struct db9_config {
47static int db9_nargs __initdata = 0; 47 int args[2];
48module_param_array_named(dev, db9, int, &db9_nargs, 0); 48 int nargs;
49MODULE_PARM_DESC(dev, "Describes first attached device (<parport#>,<type>)"); 49};
50 50
51static int db9_2[] __initdata = { -1, 0 }; 51#define DB9_MAX_PORTS 3
52static int db9_nargs_2 __initdata = 0; 52static struct db9_config db9[DB9_MAX_PORTS] __initdata;
53module_param_array_named(dev2, db9_2, int, &db9_nargs_2, 0);
54MODULE_PARM_DESC(dev2, "Describes second attached device (<parport#>,<type>)");
55 53
56static int db9_3[] __initdata = { -1, 0 }; 54module_param_array_named(dev, db9[0].args, int, &db9[0].nargs, 0);
57static int db9_nargs_3 __initdata = 0; 55MODULE_PARM_DESC(dev, "Describes first attached device (<parport#>,<type>)");
58module_param_array_named(dev3, db9_3, int, &db9_nargs_3, 0); 56module_param_array_named(dev2, db9[1].args, int, &db9[0].nargs, 0);
57MODULE_PARM_DESC(dev2, "Describes second attached device (<parport#>,<type>)");
58module_param_array_named(dev3, db9[2].args, int, &db9[2].nargs, 0);
59MODULE_PARM_DESC(dev3, "Describes third attached device (<parport#>,<type>)"); 59MODULE_PARM_DESC(dev3, "Describes third attached device (<parport#>,<type>)");
60 60
61__obsolete_setup("db9="); 61__obsolete_setup("db9=");
62__obsolete_setup("db9_2="); 62__obsolete_setup("db9_2=");
63__obsolete_setup("db9_3="); 63__obsolete_setup("db9_3=");
64 64
65#define DB9_ARG_PARPORT 0
66#define DB9_ARG_MODE 1
67
65#define DB9_MULTI_STICK 0x01 68#define DB9_MULTI_STICK 0x01
66#define DB9_MULTI2_STICK 0x02 69#define DB9_MULTI2_STICK 0x02
67#define DB9_GENESIS_PAD 0x03 70#define DB9_GENESIS_PAD 0x03
@@ -87,40 +90,53 @@ __obsolete_setup("db9_3=");
87#define DB9_NORMAL 0x0a 90#define DB9_NORMAL 0x0a
88#define DB9_NOSELECT 0x08 91#define DB9_NOSELECT 0x08
89 92
90#define DB9_MAX_DEVICES 2
91
92#define DB9_GENESIS6_DELAY 14 93#define DB9_GENESIS6_DELAY 14
93#define DB9_REFRESH_TIME HZ/100 94#define DB9_REFRESH_TIME HZ/100
94 95
96#define DB9_MAX_DEVICES 2
97
98struct db9_mode_data {
99 const char *name;
100 const short *buttons;
101 int n_buttons;
102 int n_pads;
103 int n_axis;
104 int bidirectional;
105 int reverse;
106};
107
95struct db9 { 108struct db9 {
96 struct input_dev dev[DB9_MAX_DEVICES]; 109 struct input_dev *dev[DB9_MAX_DEVICES];
97 struct timer_list timer; 110 struct timer_list timer;
98 struct pardevice *pd; 111 struct pardevice *pd;
99 int mode; 112 int mode;
100 int used; 113 int used;
101 struct semaphore sem; 114 struct semaphore sem;
102 char phys[2][32]; 115 char phys[DB9_MAX_DEVICES][32];
103}; 116};
104 117
105static struct db9 *db9_base[3]; 118static struct db9 *db9_base[3];
106 119
107static short db9_multi_btn[] = { BTN_TRIGGER, BTN_THUMB }; 120static const short db9_multi_btn[] = { BTN_TRIGGER, BTN_THUMB };
108static short db9_genesis_btn[] = { BTN_START, BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_MODE }; 121static const short db9_genesis_btn[] = { BTN_START, BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_MODE };
109static short db9_cd32_btn[] = { BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_TL, BTN_TR, BTN_START }; 122static const short db9_cd32_btn[] = { BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_TL, BTN_TR, BTN_START };
110
111static char db9_buttons[DB9_MAX_PAD] = { 0, 1, 2, 4, 0, 6, 8, 9, 1, 1, 7, 9, 9 };
112static short *db9_btn[DB9_MAX_PAD] = { NULL, db9_multi_btn, db9_multi_btn, db9_genesis_btn, NULL, db9_genesis_btn,
113 db9_genesis_btn, db9_cd32_btn, db9_multi_btn, db9_multi_btn, db9_cd32_btn,
114 db9_cd32_btn, db9_cd32_btn };
115static char *db9_name[DB9_MAX_PAD] = { NULL, "Multisystem joystick", "Multisystem joystick (2 fire)", "Genesis pad",
116 NULL, "Genesis 5 pad", "Genesis 6 pad", "Saturn pad", "Multisystem (0.8.0.2) joystick",
117 "Multisystem (0.8.0.2-dual) joystick", "Amiga CD-32 pad", "Saturn dpp", "Saturn dpp dual" };
118
119static const int db9_max_pads[DB9_MAX_PAD] = { 0, 1, 1, 1, 0, 1, 1, 6, 1, 2, 1, 6, 12 };
120static const int db9_num_axis[DB9_MAX_PAD] = { 0, 2, 2, 2, 0, 2, 2, 7, 2, 2, 2 ,7, 7 };
121static const short db9_abs[] = { ABS_X, ABS_Y, ABS_RX, ABS_RY, ABS_RZ, ABS_Z, ABS_HAT0X, ABS_HAT0Y, ABS_HAT1X, ABS_HAT1Y }; 123static const short db9_abs[] = { ABS_X, ABS_Y, ABS_RX, ABS_RY, ABS_RZ, ABS_Z, ABS_HAT0X, ABS_HAT0Y, ABS_HAT1X, ABS_HAT1Y };
122static const int db9_bidirectional[DB9_MAX_PAD] = { 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0 }; 124
123static const int db9_reverse[DB9_MAX_PAD] = { 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0 }; 125static const struct db9_mode_data db9_modes[] = {
126 { NULL, NULL, 0, 0, 0, 0, 0 },
127 { "Multisystem joystick", db9_multi_btn, 1, 1, 2, 1, 1 },
128 { "Multisystem joystick (2 fire)", db9_multi_btn, 2, 1, 2, 1, 1 },
129 { "Genesis pad", db9_genesis_btn, 4, 1, 2, 1, 1 },
130 { NULL, NULL, 0, 0, 0, 0, 0 },
131 { "Genesis 5 pad", db9_genesis_btn, 6, 1, 2, 1, 1 },
132 { "Genesis 6 pad", db9_genesis_btn, 8, 1, 2, 1, 1 },
133 { "Saturn pad", db9_cd32_btn, 9, 6, 7, 0, 1 },
134 { "Multisystem (0.8.0.2) joystick", db9_multi_btn, 1, 1, 2, 1, 1 },
135 { "Multisystem (0.8.0.2-dual) joystick", db9_multi_btn, 1, 2, 2, 1, 1 },
136 { "Amiga CD-32 pad", db9_cd32_btn, 7, 1, 2, 1, 1 },
137 { "Saturn dpp", db9_cd32_btn, 9, 6, 7, 0, 0 },
138 { "Saturn dpp dual", db9_cd32_btn, 9, 12, 7, 0, 0 },
139};
124 140
125/* 141/*
126 * Saturn controllers 142 * Saturn controllers
@@ -342,7 +358,7 @@ static int db9_saturn(int mode, struct parport *port, struct input_dev *dev)
342 default: 358 default:
343 return -1; 359 return -1;
344 } 360 }
345 max_pads = min(db9_max_pads[mode], DB9_MAX_DEVICES); 361 max_pads = min(db9_modes[mode].n_pads, DB9_MAX_DEVICES);
346 for (tmp = 0, i = 0; i < n; i++) { 362 for (tmp = 0, i = 0; i < n; i++) {
347 id = db9_saturn_read_packet(port, data, type + i, 1); 363 id = db9_saturn_read_packet(port, data, type + i, 1);
348 tmp = db9_saturn_report(id, data, dev, tmp, max_pads); 364 tmp = db9_saturn_report(id, data, dev, tmp, max_pads);
@@ -354,17 +370,18 @@ static void db9_timer(unsigned long private)
354{ 370{
355 struct db9 *db9 = (void *) private; 371 struct db9 *db9 = (void *) private;
356 struct parport *port = db9->pd->port; 372 struct parport *port = db9->pd->port;
357 struct input_dev *dev = db9->dev; 373 struct input_dev *dev = db9->dev[0];
374 struct input_dev *dev2 = db9->dev[1];
358 int data, i; 375 int data, i;
359 376
360 switch(db9->mode) { 377 switch (db9->mode) {
361 case DB9_MULTI_0802_2: 378 case DB9_MULTI_0802_2:
362 379
363 data = parport_read_data(port) >> 3; 380 data = parport_read_data(port) >> 3;
364 381
365 input_report_abs(dev + 1, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1)); 382 input_report_abs(dev2, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1));
366 input_report_abs(dev + 1, ABS_Y, (data & DB9_DOWN ? 0 : 1) - (data & DB9_UP ? 0 : 1)); 383 input_report_abs(dev2, ABS_Y, (data & DB9_DOWN ? 0 : 1) - (data & DB9_UP ? 0 : 1));
367 input_report_key(dev + 1, BTN_TRIGGER, ~data & DB9_FIRE1); 384 input_report_key(dev2, BTN_TRIGGER, ~data & DB9_FIRE1);
368 385
369 case DB9_MULTI_0802: 386 case DB9_MULTI_0802:
370 387
@@ -405,7 +422,7 @@ static void db9_timer(unsigned long private)
405 input_report_key(dev, BTN_C, ~data & DB9_FIRE2); 422 input_report_key(dev, BTN_C, ~data & DB9_FIRE2);
406 423
407 parport_write_control(port, DB9_NORMAL); 424 parport_write_control(port, DB9_NORMAL);
408 data=parport_read_data(port); 425 data = parport_read_data(port);
409 426
410 input_report_key(dev, BTN_A, ~data & DB9_FIRE1); 427 input_report_key(dev, BTN_A, ~data & DB9_FIRE1);
411 input_report_key(dev, BTN_START, ~data & DB9_FIRE2); 428 input_report_key(dev, BTN_START, ~data & DB9_FIRE2);
@@ -414,7 +431,7 @@ static void db9_timer(unsigned long private)
414 case DB9_GENESIS5_PAD: 431 case DB9_GENESIS5_PAD:
415 432
416 parport_write_control(port, DB9_NOSELECT); 433 parport_write_control(port, DB9_NOSELECT);
417 data=parport_read_data(port); 434 data = parport_read_data(port);
418 435
419 input_report_abs(dev, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1)); 436 input_report_abs(dev, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1));
420 input_report_abs(dev, ABS_Y, (data & DB9_DOWN ? 0 : 1) - (data & DB9_UP ? 0 : 1)); 437 input_report_abs(dev, ABS_Y, (data & DB9_DOWN ? 0 : 1) - (data & DB9_UP ? 0 : 1));
@@ -422,7 +439,7 @@ static void db9_timer(unsigned long private)
422 input_report_key(dev, BTN_C, ~data & DB9_FIRE2); 439 input_report_key(dev, BTN_C, ~data & DB9_FIRE2);
423 440
424 parport_write_control(port, DB9_NORMAL); 441 parport_write_control(port, DB9_NORMAL);
425 data=parport_read_data(port); 442 data = parport_read_data(port);
426 443
427 input_report_key(dev, BTN_A, ~data & DB9_FIRE1); 444 input_report_key(dev, BTN_A, ~data & DB9_FIRE1);
428 input_report_key(dev, BTN_X, ~data & DB9_FIRE2); 445 input_report_key(dev, BTN_X, ~data & DB9_FIRE2);
@@ -434,7 +451,7 @@ static void db9_timer(unsigned long private)
434 451
435 parport_write_control(port, DB9_NOSELECT); /* 1 */ 452 parport_write_control(port, DB9_NOSELECT); /* 1 */
436 udelay(DB9_GENESIS6_DELAY); 453 udelay(DB9_GENESIS6_DELAY);
437 data=parport_read_data(port); 454 data = parport_read_data(port);
438 455
439 input_report_abs(dev, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1)); 456 input_report_abs(dev, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1));
440 input_report_abs(dev, ABS_Y, (data & DB9_DOWN ? 0 : 1) - (data & DB9_UP ? 0 : 1)); 457 input_report_abs(dev, ABS_Y, (data & DB9_DOWN ? 0 : 1) - (data & DB9_UP ? 0 : 1));
@@ -443,7 +460,7 @@ static void db9_timer(unsigned long private)
443 460
444 parport_write_control(port, DB9_NORMAL); 461 parport_write_control(port, DB9_NORMAL);
445 udelay(DB9_GENESIS6_DELAY); 462 udelay(DB9_GENESIS6_DELAY);
446 data=parport_read_data(port); 463 data = parport_read_data(port);
447 464
448 input_report_key(dev, BTN_A, ~data & DB9_FIRE1); 465 input_report_key(dev, BTN_A, ~data & DB9_FIRE1);
449 input_report_key(dev, BTN_START, ~data & DB9_FIRE2); 466 input_report_key(dev, BTN_START, ~data & DB9_FIRE2);
@@ -477,7 +494,7 @@ static void db9_timer(unsigned long private)
477 494
478 case DB9_CD32_PAD: 495 case DB9_CD32_PAD:
479 496
480 data=parport_read_data(port); 497 data = parport_read_data(port);
481 498
482 input_report_abs(dev, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1)); 499 input_report_abs(dev, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1));
483 input_report_abs(dev, ABS_Y, (data & DB9_DOWN ? 0 : 1) - (data & DB9_UP ? 0 : 1)); 500 input_report_abs(dev, ABS_Y, (data & DB9_DOWN ? 0 : 1) - (data & DB9_UP ? 0 : 1));
@@ -489,7 +506,7 @@ static void db9_timer(unsigned long private)
489 parport_write_control(port, 0x02); 506 parport_write_control(port, 0x02);
490 parport_write_control(port, 0x0a); 507 parport_write_control(port, 0x0a);
491 input_report_key(dev, db9_cd32_btn[i], ~data & DB9_FIRE2); 508 input_report_key(dev, db9_cd32_btn[i], ~data & DB9_FIRE2);
492 } 509 }
493 510
494 parport_write_control(port, 0x00); 511 parport_write_control(port, 0x00);
495 break; 512 break;
@@ -513,7 +530,7 @@ static int db9_open(struct input_dev *dev)
513 if (!db9->used++) { 530 if (!db9->used++) {
514 parport_claim(db9->pd); 531 parport_claim(db9->pd);
515 parport_write_data(port, 0xff); 532 parport_write_data(port, 0xff);
516 if (db9_reverse[db9->mode]) { 533 if (db9_modes[db9->mode].reverse) {
517 parport_data_reverse(port); 534 parport_data_reverse(port);
518 parport_write_control(port, DB9_NORMAL); 535 parport_write_control(port, DB9_NORMAL);
519 } 536 }
@@ -539,117 +556,160 @@ static void db9_close(struct input_dev *dev)
539 up(&db9->sem); 556 up(&db9->sem);
540} 557}
541 558
542static struct db9 __init *db9_probe(int *config, int nargs) 559static struct db9 __init *db9_probe(int parport, int mode)
543{ 560{
544 struct db9 *db9; 561 struct db9 *db9;
562 const struct db9_mode_data *db9_mode;
545 struct parport *pp; 563 struct parport *pp;
564 struct pardevice *pd;
565 struct input_dev *input_dev;
546 int i, j; 566 int i, j;
567 int err;
547 568
548 if (config[0] < 0) 569 if (mode < 1 || mode >= DB9_MAX_PAD || !db9_modes[mode].n_buttons) {
549 return NULL; 570 printk(KERN_ERR "db9.c: Bad device type %d\n", mode);
550 571 err = -EINVAL;
551 if (nargs < 2) { 572 goto err_out;
552 printk(KERN_ERR "db9.c: Device type must be specified.\n");
553 return NULL;
554 } 573 }
555 574
556 if (config[1] < 1 || config[1] >= DB9_MAX_PAD || !db9_buttons[config[1]]) { 575 db9_mode = &db9_modes[mode];
557 printk(KERN_ERR "db9.c: bad config\n");
558 return NULL;
559 }
560 576
561 pp = parport_find_number(config[0]); 577 pp = parport_find_number(parport);
562 if (!pp) { 578 if (!pp) {
563 printk(KERN_ERR "db9.c: no such parport\n"); 579 printk(KERN_ERR "db9.c: no such parport\n");
564 return NULL; 580 err = -ENODEV;
581 goto err_out;
565 } 582 }
566 583
567 if (db9_bidirectional[config[1]]) { 584 if (db9_mode[mode].bidirectional && !(pp->modes & PARPORT_MODE_TRISTATE)) {
568 if (!(pp->modes & PARPORT_MODE_TRISTATE)) { 585 printk(KERN_ERR "db9.c: specified parport is not bidirectional\n");
569 printk(KERN_ERR "db9.c: specified parport is not bidirectional\n"); 586 err = -EINVAL;
570 parport_put_port(pp); 587 goto err_put_pp;
571 return NULL; 588 }
572 } 589
590 pd = parport_register_device(pp, "db9", NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL);
591 if (!pd) {
592 printk(KERN_ERR "db9.c: parport busy already - lp.o loaded?\n");
593 err = -EBUSY;
594 goto err_put_pp;
573 } 595 }
574 596
575 if (!(db9 = kzalloc(sizeof(struct db9), GFP_KERNEL))) { 597 db9 = kzalloc(sizeof(struct db9), GFP_KERNEL);
576 parport_put_port(pp); 598 if (!db9) {
577 return NULL; 599 printk(KERN_ERR "db9.c: Not enough memory\n");
600 err = -ENOMEM;
601 goto err_unreg_pardev;
578 } 602 }
579 603
580 init_MUTEX(&db9->sem); 604 init_MUTEX(&db9->sem);
581 db9->mode = config[1]; 605 db9->pd = pd;
606 db9->mode = mode;
582 init_timer(&db9->timer); 607 init_timer(&db9->timer);
583 db9->timer.data = (long) db9; 608 db9->timer.data = (long) db9;
584 db9->timer.function = db9_timer; 609 db9->timer.function = db9_timer;
585 610
586 db9->pd = parport_register_device(pp, "db9", NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL); 611 for (i = 0; i < (min(db9_mode->n_pads, DB9_MAX_DEVICES)); i++) {
587 parport_put_port(pp);
588
589 if (!db9->pd) {
590 printk(KERN_ERR "db9.c: parport busy already - lp.o loaded?\n");
591 kfree(db9);
592 return NULL;
593 }
594 612
595 for (i = 0; i < (min(db9_max_pads[db9->mode], DB9_MAX_DEVICES)); i++) { 613 db9->dev[i] = input_dev = input_allocate_device();
614 if (!input_dev) {
615 printk(KERN_ERR "db9.c: Not enough memory for input device\n");
616 err = -ENOMEM;
617 goto err_free_devs;
618 }
596 619
597 sprintf(db9->phys[i], "%s/input%d", db9->pd->port->name, i); 620 sprintf(db9->phys[i], "%s/input%d", db9->pd->port->name, i);
598 621
599 db9->dev[i].private = db9; 622 input_dev->name = db9_mode->name;
600 db9->dev[i].open = db9_open; 623 input_dev->phys = db9->phys[i];
601 db9->dev[i].close = db9_close; 624 input_dev->id.bustype = BUS_PARPORT;
602 625 input_dev->id.vendor = 0x0002;
603 db9->dev[i].name = db9_name[db9->mode]; 626 input_dev->id.product = mode;
604 db9->dev[i].phys = db9->phys[i]; 627 input_dev->id.version = 0x0100;
605 db9->dev[i].id.bustype = BUS_PARPORT; 628 input_dev->private = db9;
606 db9->dev[i].id.vendor = 0x0002; 629
607 db9->dev[i].id.product = config[1]; 630 input_dev->open = db9_open;
608 db9->dev[i].id.version = 0x0100; 631 input_dev->close = db9_close;
609 632
610 db9->dev[i].evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 633 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
611 for (j = 0; j < db9_buttons[db9->mode]; j++) 634 for (j = 0; j < db9_mode->n_buttons; j++)
612 set_bit(db9_btn[db9->mode][j], db9->dev[i].keybit); 635 set_bit(db9_mode->buttons[j], input_dev->keybit);
613 for (j = 0; j < db9_num_axis[db9->mode]; j++) { 636 for (j = 0; j < db9_mode->n_axis; j++) {
614 set_bit(db9_abs[j], db9->dev[i].absbit); 637 if (j < 2)
615 if (j < 2) { 638 input_set_abs_params(input_dev, db9_abs[j], -1, 1, 0, 0);
616 db9->dev[i].absmin[db9_abs[j]] = -1; 639 else
617 db9->dev[i].absmax[db9_abs[j]] = 1; 640 input_set_abs_params(input_dev, db9_abs[j], 1, 255, 0, 0);
618 } else {
619 db9->dev[i].absmin[db9_abs[j]] = 1;
620 db9->dev[i].absmax[db9_abs[j]] = 255;
621 db9->dev[i].absflat[db9_abs[j]] = 0;
622 }
623 } 641 }
624 input_register_device(db9->dev + i); 642
625 printk(KERN_INFO "input: %s on %s\n", db9->dev[i].name, db9->pd->port->name); 643 input_register_device(input_dev);
626 } 644 }
627 645
646 parport_put_port(pp);
628 return db9; 647 return db9;
648
649 err_free_devs:
650 while (--i >= 0)
651 input_unregister_device(db9->dev[i]);
652 kfree(db9);
653 err_unreg_pardev:
654 parport_unregister_device(pd);
655 err_put_pp:
656 parport_put_port(pp);
657 err_out:
658 return ERR_PTR(err);
659}
660
661static void __exit db9_remove(struct db9 *db9)
662{
663 int i;
664
665 for (i = 0; i < min(db9_modes[db9->mode].n_pads, DB9_MAX_DEVICES); i++)
666 input_unregister_device(db9->dev[i]);
667 parport_unregister_device(db9->pd);
668 kfree(db9);
629} 669}
630 670
631static int __init db9_init(void) 671static int __init db9_init(void)
632{ 672{
633 db9_base[0] = db9_probe(db9, db9_nargs); 673 int i;
634 db9_base[1] = db9_probe(db9_2, db9_nargs_2); 674 int have_dev = 0;
635 db9_base[2] = db9_probe(db9_3, db9_nargs_3); 675 int err = 0;
676
677 for (i = 0; i < DB9_MAX_PORTS; i++) {
678 if (db9[i].nargs == 0 || db9[i].args[DB9_ARG_PARPORT] < 0)
679 continue;
680
681 if (db9[i].nargs < 2) {
682 printk(KERN_ERR "db9.c: Device type must be specified.\n");
683 err = -EINVAL;
684 break;
685 }
686
687 db9_base[i] = db9_probe(db9[i].args[DB9_ARG_PARPORT],
688 db9[i].args[DB9_ARG_MODE]);
689 if (IS_ERR(db9_base[i])) {
690 err = PTR_ERR(db9_base[i]);
691 break;
692 }
693
694 have_dev = 1;
695 }
636 696
637 if (db9_base[0] || db9_base[1] || db9_base[2]) 697 if (err) {
638 return 0; 698 while (--i >= 0)
699 db9_remove(db9_base[i]);
700 return err;
701 }
639 702
640 return -ENODEV; 703 return have_dev ? 0 : -ENODEV;
641} 704}
642 705
643static void __exit db9_exit(void) 706static void __exit db9_exit(void)
644{ 707{
645 int i, j; 708 int i;
646 709
647 for (i = 0; i < 3; i++) 710 for (i = 0; i < DB9_MAX_PORTS; i++)
648 if (db9_base[i]) { 711 if (db9_base[i])
649 for (j = 0; j < min(db9_max_pads[db9_base[i]->mode], DB9_MAX_DEVICES); j++) 712 db9_remove(db9_base[i]);
650 input_unregister_device(db9_base[i]->dev + j);
651 parport_unregister_device(db9_base[i]->pd);
652 }
653} 713}
654 714
655module_init(db9_init); 715module_init(db9_init);
diff --git a/drivers/input/joystick/gamecon.c b/drivers/input/joystick/gamecon.c
index 5427bf9fc862..7df2d82f2c83 100644
--- a/drivers/input/joystick/gamecon.c
+++ b/drivers/input/joystick/gamecon.c
@@ -41,20 +41,22 @@ MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
41MODULE_DESCRIPTION("NES, SNES, N64, MultiSystem, PSX gamepad driver"); 41MODULE_DESCRIPTION("NES, SNES, N64, MultiSystem, PSX gamepad driver");
42MODULE_LICENSE("GPL"); 42MODULE_LICENSE("GPL");
43 43
44static int gc[] __initdata = { -1, 0, 0, 0, 0, 0 }; 44#define GC_MAX_PORTS 3
45static int gc_nargs __initdata = 0; 45#define GC_MAX_DEVICES 5
46module_param_array_named(map, gc, int, &gc_nargs, 0);
47MODULE_PARM_DESC(map, "Describers first set of devices (<parport#>,<pad1>,<pad2>,..<pad5>)");
48 46
49static int gc_2[] __initdata = { -1, 0, 0, 0, 0, 0 }; 47struct gc_config {
50static int gc_nargs_2 __initdata = 0; 48 int args[GC_MAX_DEVICES + 1];
51module_param_array_named(map2, gc_2, int, &gc_nargs_2, 0); 49 int nargs;
52MODULE_PARM_DESC(map2, "Describers second set of devices"); 50};
51
52static struct gc_config gc[GC_MAX_PORTS] __initdata;
53 53
54static int gc_3[] __initdata = { -1, 0, 0, 0, 0, 0 }; 54module_param_array_named(map, gc[0].args, int, &gc[0].nargs, 0);
55static int gc_nargs_3 __initdata = 0; 55MODULE_PARM_DESC(map, "Describes first set of devices (<parport#>,<pad1>,<pad2>,..<pad5>)");
56module_param_array_named(map3, gc_3, int, &gc_nargs_3, 0); 56module_param_array_named(map2, gc[1].args, int, &gc[1].nargs, 0);
57MODULE_PARM_DESC(map3, "Describers third set of devices"); 57MODULE_PARM_DESC(map2, "Describes second set of devices");
58module_param_array_named(map3, gc[2].args, int, &gc[2].nargs, 0);
59MODULE_PARM_DESC(map3, "Describes third set of devices");
58 60
59__obsolete_setup("gc="); 61__obsolete_setup("gc=");
60__obsolete_setup("gc_2="); 62__obsolete_setup("gc_2=");
@@ -77,12 +79,12 @@ __obsolete_setup("gc_3=");
77 79
78struct gc { 80struct gc {
79 struct pardevice *pd; 81 struct pardevice *pd;
80 struct input_dev dev[5]; 82 struct input_dev *dev[GC_MAX_DEVICES];
81 struct timer_list timer; 83 struct timer_list timer;
82 unsigned char pads[GC_MAX + 1]; 84 unsigned char pads[GC_MAX + 1];
83 int used; 85 int used;
84 struct semaphore sem; 86 struct semaphore sem;
85 char phys[5][32]; 87 char phys[GC_MAX_DEVICES][32];
86}; 88};
87 89
88static struct gc *gc_base[3]; 90static struct gc *gc_base[3];
@@ -330,7 +332,6 @@ static void gc_psx_read_packet(struct gc *gc, unsigned char data[5][GC_PSX_BYTES
330static void gc_timer(unsigned long private) 332static void gc_timer(unsigned long private)
331{ 333{
332 struct gc *gc = (void *) private; 334 struct gc *gc = (void *) private;
333 struct input_dev *dev = gc->dev;
334 unsigned char data[GC_MAX_LENGTH]; 335 unsigned char data[GC_MAX_LENGTH];
335 unsigned char data_psx[5][GC_PSX_BYTES]; 336 unsigned char data_psx[5][GC_PSX_BYTES];
336 int i, j, s; 337 int i, j, s;
@@ -357,16 +358,16 @@ static void gc_timer(unsigned long private)
357 if (data[31 - j] & s) axes[1] |= 1 << j; 358 if (data[31 - j] & s) axes[1] |= 1 << j;
358 } 359 }
359 360
360 input_report_abs(dev + i, ABS_X, axes[0]); 361 input_report_abs(gc->dev[i], ABS_X, axes[0]);
361 input_report_abs(dev + i, ABS_Y, -axes[1]); 362 input_report_abs(gc->dev[i], ABS_Y, -axes[1]);
362 363
363 input_report_abs(dev + i, ABS_HAT0X, !(s & data[6]) - !(s & data[7])); 364 input_report_abs(gc->dev[i], ABS_HAT0X, !(s & data[6]) - !(s & data[7]));
364 input_report_abs(dev + i, ABS_HAT0Y, !(s & data[4]) - !(s & data[5])); 365 input_report_abs(gc->dev[i], ABS_HAT0Y, !(s & data[4]) - !(s & data[5]));
365 366
366 for (j = 0; j < 10; j++) 367 for (j = 0; j < 10; j++)
367 input_report_key(dev + i, gc_n64_btn[j], s & data[gc_n64_bytes[j]]); 368 input_report_key(gc->dev[i], gc_n64_btn[j], s & data[gc_n64_bytes[j]]);
368 369
369 input_sync(dev + i); 370 input_sync(gc->dev[i]);
370 } 371 }
371 } 372 }
372 } 373 }
@@ -384,19 +385,19 @@ static void gc_timer(unsigned long private)
384 s = gc_status_bit[i]; 385 s = gc_status_bit[i];
385 386
386 if (s & (gc->pads[GC_NES] | gc->pads[GC_SNES])) { 387 if (s & (gc->pads[GC_NES] | gc->pads[GC_SNES])) {
387 input_report_abs(dev + i, ABS_X, !(s & data[6]) - !(s & data[7])); 388 input_report_abs(gc->dev[i], ABS_X, !(s & data[6]) - !(s & data[7]));
388 input_report_abs(dev + i, ABS_Y, !(s & data[4]) - !(s & data[5])); 389 input_report_abs(gc->dev[i], ABS_Y, !(s & data[4]) - !(s & data[5]));
389 } 390 }
390 391
391 if (s & gc->pads[GC_NES]) 392 if (s & gc->pads[GC_NES])
392 for (j = 0; j < 4; j++) 393 for (j = 0; j < 4; j++)
393 input_report_key(dev + i, gc_snes_btn[j], s & data[gc_nes_bytes[j]]); 394 input_report_key(gc->dev[i], gc_snes_btn[j], s & data[gc_nes_bytes[j]]);
394 395
395 if (s & gc->pads[GC_SNES]) 396 if (s & gc->pads[GC_SNES])
396 for (j = 0; j < 8; j++) 397 for (j = 0; j < 8; j++)
397 input_report_key(dev + i, gc_snes_btn[j], s & data[gc_snes_bytes[j]]); 398 input_report_key(gc->dev[i], gc_snes_btn[j], s & data[gc_snes_bytes[j]]);
398 399
399 input_sync(dev + i); 400 input_sync(gc->dev[i]);
400 } 401 }
401 } 402 }
402 403
@@ -413,15 +414,15 @@ static void gc_timer(unsigned long private)
413 s = gc_status_bit[i]; 414 s = gc_status_bit[i];
414 415
415 if (s & (gc->pads[GC_MULTI] | gc->pads[GC_MULTI2])) { 416 if (s & (gc->pads[GC_MULTI] | gc->pads[GC_MULTI2])) {
416 input_report_abs(dev + i, ABS_X, !(s & data[2]) - !(s & data[3])); 417 input_report_abs(gc->dev[i], ABS_X, !(s & data[2]) - !(s & data[3]));
417 input_report_abs(dev + i, ABS_Y, !(s & data[0]) - !(s & data[1])); 418 input_report_abs(gc->dev[i], ABS_Y, !(s & data[0]) - !(s & data[1]));
418 input_report_key(dev + i, BTN_TRIGGER, s & data[4]); 419 input_report_key(gc->dev[i], BTN_TRIGGER, s & data[4]);
419 } 420 }
420 421
421 if (s & gc->pads[GC_MULTI2]) 422 if (s & gc->pads[GC_MULTI2])
422 input_report_key(dev + i, BTN_THUMB, s & data[5]); 423 input_report_key(gc->dev[i], BTN_THUMB, s & data[5]);
423 424
424 input_sync(dev + i); 425 input_sync(gc->dev[i]);
425 } 426 }
426 } 427 }
427 428
@@ -438,44 +439,44 @@ static void gc_timer(unsigned long private)
438 439
439 case GC_PSX_RUMBLE: 440 case GC_PSX_RUMBLE:
440 441
441 input_report_key(dev + i, BTN_THUMBL, ~data_psx[i][0] & 0x04); 442 input_report_key(gc->dev[i], BTN_THUMBL, ~data_psx[i][0] & 0x04);
442 input_report_key(dev + i, BTN_THUMBR, ~data_psx[i][0] & 0x02); 443 input_report_key(gc->dev[i], BTN_THUMBR, ~data_psx[i][0] & 0x02);
443 444
444 case GC_PSX_NEGCON: 445 case GC_PSX_NEGCON:
445 case GC_PSX_ANALOG: 446 case GC_PSX_ANALOG:
446 447
447 if(gc->pads[GC_DDR] & gc_status_bit[i]) { 448 if (gc->pads[GC_DDR] & gc_status_bit[i]) {
448 for(j = 0; j < 4; j++) 449 for(j = 0; j < 4; j++)
449 input_report_key(dev + i, gc_psx_ddr_btn[j], ~data_psx[i][0] & (0x10 << j)); 450 input_report_key(gc->dev[i], gc_psx_ddr_btn[j], ~data_psx[i][0] & (0x10 << j));
450 } else { 451 } else {
451 for (j = 0; j < 4; j++) 452 for (j = 0; j < 4; j++)
452 input_report_abs(dev + i, gc_psx_abs[j+2], data_psx[i][j + 2]); 453 input_report_abs(gc->dev[i], gc_psx_abs[j+2], data_psx[i][j + 2]);
453 454
454 input_report_abs(dev + i, ABS_X, 128 + !(data_psx[i][0] & 0x20) * 127 - !(data_psx[i][0] & 0x80) * 128); 455 input_report_abs(gc->dev[i], ABS_X, 128 + !(data_psx[i][0] & 0x20) * 127 - !(data_psx[i][0] & 0x80) * 128);
455 input_report_abs(dev + i, ABS_Y, 128 + !(data_psx[i][0] & 0x40) * 127 - !(data_psx[i][0] & 0x10) * 128); 456 input_report_abs(gc->dev[i], ABS_Y, 128 + !(data_psx[i][0] & 0x40) * 127 - !(data_psx[i][0] & 0x10) * 128);
456 } 457 }
457 458
458 for (j = 0; j < 8; j++) 459 for (j = 0; j < 8; j++)
459 input_report_key(dev + i, gc_psx_btn[j], ~data_psx[i][1] & (1 << j)); 460 input_report_key(gc->dev[i], gc_psx_btn[j], ~data_psx[i][1] & (1 << j));
460 461
461 input_report_key(dev + i, BTN_START, ~data_psx[i][0] & 0x08); 462 input_report_key(gc->dev[i], BTN_START, ~data_psx[i][0] & 0x08);
462 input_report_key(dev + i, BTN_SELECT, ~data_psx[i][0] & 0x01); 463 input_report_key(gc->dev[i], BTN_SELECT, ~data_psx[i][0] & 0x01);
463 464
464 input_sync(dev + i); 465 input_sync(gc->dev[i]);
465 466
466 break; 467 break;
467 468
468 case GC_PSX_NORMAL: 469 case GC_PSX_NORMAL:
469 if(gc->pads[GC_DDR] & gc_status_bit[i]) { 470 if (gc->pads[GC_DDR] & gc_status_bit[i]) {
470 for(j = 0; j < 4; j++) 471 for(j = 0; j < 4; j++)
471 input_report_key(dev + i, gc_psx_ddr_btn[j], ~data_psx[i][0] & (0x10 << j)); 472 input_report_key(gc->dev[i], gc_psx_ddr_btn[j], ~data_psx[i][0] & (0x10 << j));
472 } else { 473 } else {
473 input_report_abs(dev + i, ABS_X, 128 + !(data_psx[i][0] & 0x20) * 127 - !(data_psx[i][0] & 0x80) * 128); 474 input_report_abs(gc->dev[i], ABS_X, 128 + !(data_psx[i][0] & 0x20) * 127 - !(data_psx[i][0] & 0x80) * 128);
474 input_report_abs(dev + i, ABS_Y, 128 + !(data_psx[i][0] & 0x40) * 127 - !(data_psx[i][0] & 0x10) * 128); 475 input_report_abs(gc->dev[i], ABS_Y, 128 + !(data_psx[i][0] & 0x40) * 127 - !(data_psx[i][0] & 0x10) * 128);
475 476
476 /* for some reason if the extra axes are left unset they drift */ 477 /* for some reason if the extra axes are left unset they drift */
477 /* for (j = 0; j < 4; j++) 478 /* for (j = 0; j < 4; j++)
478 input_report_abs(dev + i, gc_psx_abs[j+2], 128); 479 input_report_abs(gc->dev[i], gc_psx_abs[j+2], 128);
479 * This needs to be debugged properly, 480 * This needs to be debugged properly,
480 * maybe fuzz processing needs to be done in input_sync() 481 * maybe fuzz processing needs to be done in input_sync()
481 * --vojtech 482 * --vojtech
@@ -483,12 +484,12 @@ static void gc_timer(unsigned long private)
483 } 484 }
484 485
485 for (j = 0; j < 8; j++) 486 for (j = 0; j < 8; j++)
486 input_report_key(dev + i, gc_psx_btn[j], ~data_psx[i][1] & (1 << j)); 487 input_report_key(gc->dev[i], gc_psx_btn[j], ~data_psx[i][1] & (1 << j));
487 488
488 input_report_key(dev + i, BTN_START, ~data_psx[i][0] & 0x08); 489 input_report_key(gc->dev[i], BTN_START, ~data_psx[i][0] & 0x08);
489 input_report_key(dev + i, BTN_SELECT, ~data_psx[i][0] & 0x01); 490 input_report_key(gc->dev[i], BTN_SELECT, ~data_psx[i][0] & 0x01);
490 491
491 input_sync(dev + i); 492 input_sync(gc->dev[i]);
492 493
493 break; 494 break;
494 495
@@ -533,177 +534,212 @@ static void gc_close(struct input_dev *dev)
533 up(&gc->sem); 534 up(&gc->sem);
534} 535}
535 536
536static struct gc __init *gc_probe(int *config, int nargs) 537static int __init gc_setup_pad(struct gc *gc, int idx, int pad_type)
537{ 538{
538 struct gc *gc; 539 struct input_dev *input_dev;
539 struct parport *pp; 540 int i;
540 int i, j;
541 541
542 if (config[0] < 0) 542 if (!pad_type)
543 return NULL; 543 return 0;
544 544
545 if (nargs < 2) { 545 if (pad_type < 1 || pad_type > GC_MAX) {
546 printk(KERN_ERR "gamecon.c: at least one device must be specified\n"); 546 printk(KERN_WARNING "gamecon.c: Pad type %d unknown\n", pad_type);
547 return NULL; 547 return -EINVAL;
548 } 548 }
549 549
550 pp = parport_find_number(config[0]); 550 gc->dev[idx] = input_dev = input_allocate_device();
551 551 if (!input_dev) {
552 if (!pp) { 552 printk(KERN_ERR "gamecon.c: Not enough memory for input device\n");
553 printk(KERN_ERR "gamecon.c: no such parport\n"); 553 return -ENOMEM;
554 return NULL;
555 } 554 }
556 555
557 if (!(gc = kzalloc(sizeof(struct gc), GFP_KERNEL))) { 556 input_dev->name = gc_names[pad_type];
558 parport_put_port(pp); 557 input_dev->phys = gc->phys[idx];
559 return NULL; 558 input_dev->id.bustype = BUS_PARPORT;
559 input_dev->id.vendor = 0x0001;
560 input_dev->id.product = pad_type;
561 input_dev->id.version = 0x0100;
562 input_dev->private = gc;
563
564 input_dev->open = gc_open;
565 input_dev->close = gc_close;
566
567 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
568
569 for (i = 0; i < 2; i++)
570 input_set_abs_params(input_dev, ABS_X + i, -1, 1, 0, 0);
571
572 gc->pads[0] |= gc_status_bit[idx];
573 gc->pads[pad_type] |= gc_status_bit[idx];
574
575 switch (pad_type) {
576
577 case GC_N64:
578 for (i = 0; i < 10; i++)
579 set_bit(gc_n64_btn[i], input_dev->keybit);
580
581 for (i = 0; i < 2; i++) {
582 input_set_abs_params(input_dev, ABS_X + i, -127, 126, 0, 2);
583 input_set_abs_params(input_dev, ABS_HAT0X + i, -1, 1, 0, 0);
584 }
585
586 break;
587
588 case GC_SNES:
589 for (i = 4; i < 8; i++)
590 set_bit(gc_snes_btn[i], input_dev->keybit);
591 case GC_NES:
592 for (i = 0; i < 4; i++)
593 set_bit(gc_snes_btn[i], input_dev->keybit);
594 break;
595
596 case GC_MULTI2:
597 set_bit(BTN_THUMB, input_dev->keybit);
598 case GC_MULTI:
599 set_bit(BTN_TRIGGER, input_dev->keybit);
600 break;
601
602 case GC_PSX:
603 for (i = 0; i < 6; i++)
604 input_set_abs_params(input_dev, gc_psx_abs[i], 4, 252, 0, 2);
605 for (i = 0; i < 12; i++)
606 set_bit(gc_psx_btn[i], input_dev->keybit);
607
608 break;
609
610 case GC_DDR:
611 for (i = 0; i < 4; i++)
612 set_bit(gc_psx_ddr_btn[i], input_dev->keybit);
613 for (i = 0; i < 12; i++)
614 set_bit(gc_psx_btn[i], input_dev->keybit);
615
616 break;
560 } 617 }
561 618
562 init_MUTEX(&gc->sem); 619 return 0;
620}
563 621
564 gc->pd = parport_register_device(pp, "gamecon", NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL); 622static struct gc __init *gc_probe(int parport, int *pads, int n_pads)
623{
624 struct gc *gc;
625 struct parport *pp;
626 struct pardevice *pd;
627 int i;
628 int err;
565 629
566 parport_put_port(pp); 630 pp = parport_find_number(parport);
631 if (!pp) {
632 printk(KERN_ERR "gamecon.c: no such parport\n");
633 err = -EINVAL;
634 goto err_out;
635 }
567 636
568 if (!gc->pd) { 637 pd = parport_register_device(pp, "gamecon", NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL);
638 if (!pd) {
569 printk(KERN_ERR "gamecon.c: parport busy already - lp.o loaded?\n"); 639 printk(KERN_ERR "gamecon.c: parport busy already - lp.o loaded?\n");
570 kfree(gc); 640 err = -EBUSY;
571 return NULL; 641 goto err_put_pp;
572 } 642 }
573 643
574 parport_claim(gc->pd); 644 gc = kzalloc(sizeof(struct gc), GFP_KERNEL);
645 if (!gc) {
646 printk(KERN_ERR "gamecon.c: Not enough memory\n");
647 err = -ENOMEM;
648 goto err_unreg_pardev;
649 }
575 650
651 init_MUTEX(&gc->sem);
652 gc->pd = pd;
576 init_timer(&gc->timer); 653 init_timer(&gc->timer);
577 gc->timer.data = (long) gc; 654 gc->timer.data = (long) gc;
578 gc->timer.function = gc_timer; 655 gc->timer.function = gc_timer;
579 656
580 for (i = 0; i < nargs - 1; i++) { 657 for (i = 0; i < n_pads; i++) {
581 658 if (!pads[i])
582 if (!config[i + 1])
583 continue; 659 continue;
584 660
585 if (config[i + 1] < 1 || config[i + 1] > GC_MAX) { 661 sprintf(gc->phys[i], "%s/input%d", gc->pd->port->name, i);
586 printk(KERN_WARNING "gamecon.c: Pad type %d unknown\n", config[i + 1]); 662 err = gc_setup_pad(gc, i, pads[i]);
587 continue; 663 if (err)
588 } 664 goto err_free_devs;
589
590 gc->dev[i].private = gc;
591 gc->dev[i].open = gc_open;
592 gc->dev[i].close = gc_close;
593 665
594 gc->dev[i].evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 666 input_register_device(gc->dev[i]);
667 }
595 668
596 for (j = 0; j < 2; j++) { 669 if (!gc->pads[0]) {
597 set_bit(ABS_X + j, gc->dev[i].absbit); 670 printk(KERN_ERR "gamecon.c: No valid devices specified\n");
598 gc->dev[i].absmin[ABS_X + j] = -1; 671 err = -EINVAL;
599 gc->dev[i].absmax[ABS_X + j] = 1; 672 goto err_free_gc;
600 } 673 }
601 674
602 gc->pads[0] |= gc_status_bit[i]; 675 parport_put_port(pp);
603 gc->pads[config[i + 1]] |= gc_status_bit[i]; 676 return gc;
604 677
605 switch(config[i + 1]) { 678 err_free_devs:
679 while (--i >= 0)
680 input_unregister_device(gc->dev[i]);
681 err_free_gc:
682 kfree(gc);
683 err_unreg_pardev:
684 parport_unregister_device(pd);
685 err_put_pp:
686 parport_put_port(pp);
687 err_out:
688 return ERR_PTR(err);
689}
606 690
607 case GC_N64: 691static void __exit gc_remove(struct gc *gc)
608 for (j = 0; j < 10; j++) 692{
609 set_bit(gc_n64_btn[j], gc->dev[i].keybit); 693 int i;
610
611 for (j = 0; j < 2; j++) {
612 set_bit(ABS_X + j, gc->dev[i].absbit);
613 gc->dev[i].absmin[ABS_X + j] = -127;
614 gc->dev[i].absmax[ABS_X + j] = 126;
615 gc->dev[i].absflat[ABS_X + j] = 2;
616 set_bit(ABS_HAT0X + j, gc->dev[i].absbit);
617 gc->dev[i].absmin[ABS_HAT0X + j] = -1;
618 gc->dev[i].absmax[ABS_HAT0X + j] = 1;
619 }
620 694
621 break; 695 for (i = 0; i < GC_MAX_DEVICES; i++)
696 if (gc->dev[i])
697 input_unregister_device(gc->dev[i]);
698 parport_unregister_device(gc->pd);
699 kfree(gc);
700}
622 701
623 case GC_SNES: 702static int __init gc_init(void)
624 for (j = 4; j < 8; j++) 703{
625 set_bit(gc_snes_btn[j], gc->dev[i].keybit); 704 int i;
626 case GC_NES: 705 int have_dev = 0;
627 for (j = 0; j < 4; j++) 706 int err = 0;
628 set_bit(gc_snes_btn[j], gc->dev[i].keybit);
629 break;
630
631 case GC_MULTI2:
632 set_bit(BTN_THUMB, gc->dev[i].keybit);
633 case GC_MULTI:
634 set_bit(BTN_TRIGGER, gc->dev[i].keybit);
635 break;
636
637 case GC_PSX:
638 case GC_DDR:
639 if(config[i + 1] == GC_DDR) {
640 for (j = 0; j < 4; j++)
641 set_bit(gc_psx_ddr_btn[j], gc->dev[i].keybit);
642 } else {
643 for (j = 0; j < 6; j++) {
644 set_bit(gc_psx_abs[j], gc->dev[i].absbit);
645 gc->dev[i].absmin[gc_psx_abs[j]] = 4;
646 gc->dev[i].absmax[gc_psx_abs[j]] = 252;
647 gc->dev[i].absflat[gc_psx_abs[j]] = 2;
648 }
649 }
650 707
651 for (j = 0; j < 12; j++) 708 for (i = 0; i < GC_MAX_PORTS; i++) {
652 set_bit(gc_psx_btn[j], gc->dev[i].keybit); 709 if (gc[i].nargs == 0 || gc[i].args[0] < 0)
710 continue;
653 711
654 break; 712 if (gc[i].nargs < 2) {
713 printk(KERN_ERR "gamecon.c: at least one device must be specified\n");
714 err = -EINVAL;
715 break;
655 } 716 }
656 717
657 sprintf(gc->phys[i], "%s/input%d", gc->pd->port->name, i); 718 gc_base[i] = gc_probe(gc[i].args[0], gc[i].args + 1, gc[i].nargs - 1);
719 if (IS_ERR(gc_base[i])) {
720 err = PTR_ERR(gc_base[i]);
721 break;
722 }
658 723
659 gc->dev[i].name = gc_names[config[i + 1]]; 724 have_dev = 1;
660 gc->dev[i].phys = gc->phys[i];
661 gc->dev[i].id.bustype = BUS_PARPORT;
662 gc->dev[i].id.vendor = 0x0001;
663 gc->dev[i].id.product = config[i + 1];
664 gc->dev[i].id.version = 0x0100;
665 } 725 }
666 726
667 parport_release(gc->pd); 727 if (err) {
668 728 while (--i >= 0)
669 if (!gc->pads[0]) { 729 gc_remove(gc_base[i]);
670 parport_unregister_device(gc->pd); 730 return err;
671 kfree(gc);
672 return NULL;
673 } 731 }
674 732
675 for (i = 0; i < 5; i++) 733 return have_dev ? 0 : -ENODEV;
676 if (gc->pads[0] & gc_status_bit[i]) {
677 input_register_device(gc->dev + i);
678 printk(KERN_INFO "input: %s on %s\n", gc->dev[i].name, gc->pd->port->name);
679 }
680
681 return gc;
682}
683
684static int __init gc_init(void)
685{
686 gc_base[0] = gc_probe(gc, gc_nargs);
687 gc_base[1] = gc_probe(gc_2, gc_nargs_2);
688 gc_base[2] = gc_probe(gc_3, gc_nargs_3);
689
690 if (gc_base[0] || gc_base[1] || gc_base[2])
691 return 0;
692
693 return -ENODEV;
694} 734}
695 735
696static void __exit gc_exit(void) 736static void __exit gc_exit(void)
697{ 737{
698 int i, j; 738 int i;
699 739
700 for (i = 0; i < 3; i++) 740 for (i = 0; i < GC_MAX_PORTS; i++)
701 if (gc_base[i]) { 741 if (gc_base[i])
702 for (j = 0; j < 5; j++) 742 gc_remove(gc_base[i]);
703 if (gc_base[i]->pads[0] & gc_status_bit[j])
704 input_unregister_device(gc_base[i]->dev + j);
705 parport_unregister_device(gc_base[i]->pd);
706 }
707} 743}
708 744
709module_init(gc_init); 745module_init(gc_init);
diff --git a/drivers/input/joystick/gf2k.c b/drivers/input/joystick/gf2k.c
index 8e4f92b115e6..e151f8c5bcb9 100644
--- a/drivers/input/joystick/gf2k.c
+++ b/drivers/input/joystick/gf2k.c
@@ -81,7 +81,7 @@ static short gf2k_seq_digital[] = { 590, 320, 860, 0 };
81 81
82struct gf2k { 82struct gf2k {
83 struct gameport *gameport; 83 struct gameport *gameport;
84 struct input_dev dev; 84 struct input_dev *dev;
85 int reads; 85 int reads;
86 int bads; 86 int bads;
87 unsigned char id; 87 unsigned char id;
@@ -175,7 +175,7 @@ static int gf2k_get_bits(unsigned char *buf, int pos, int num, int shift)
175 175
176static void gf2k_read(struct gf2k *gf2k, unsigned char *data) 176static void gf2k_read(struct gf2k *gf2k, unsigned char *data)
177{ 177{
178 struct input_dev *dev = &gf2k->dev; 178 struct input_dev *dev = gf2k->dev;
179 int i, t; 179 int i, t;
180 180
181 for (i = 0; i < 4 && i < gf2k_axes[gf2k->id]; i++) 181 for (i = 0; i < 4 && i < gf2k_axes[gf2k->id]; i++)
@@ -239,13 +239,19 @@ static void gf2k_close(struct input_dev *dev)
239static int gf2k_connect(struct gameport *gameport, struct gameport_driver *drv) 239static int gf2k_connect(struct gameport *gameport, struct gameport_driver *drv)
240{ 240{
241 struct gf2k *gf2k; 241 struct gf2k *gf2k;
242 struct input_dev *input_dev;
242 unsigned char data[GF2K_LENGTH]; 243 unsigned char data[GF2K_LENGTH];
243 int i, err; 244 int i, err;
244 245
245 if (!(gf2k = kzalloc(sizeof(struct gf2k), GFP_KERNEL))) 246 gf2k = kzalloc(sizeof(struct gf2k), GFP_KERNEL);
246 return -ENOMEM; 247 input_dev = input_allocate_device();
248 if (!gf2k || !input_dev) {
249 err = -ENOMEM;
250 goto fail1;
251 }
247 252
248 gf2k->gameport = gameport; 253 gf2k->gameport = gameport;
254 gf2k->dev = input_dev;
249 255
250 gameport_set_drvdata(gameport, gf2k); 256 gameport_set_drvdata(gameport, gf2k);
251 257
@@ -295,53 +301,52 @@ static int gf2k_connect(struct gameport *gameport, struct gameport_driver *drv)
295 301
296 gf2k->length = gf2k_lens[gf2k->id]; 302 gf2k->length = gf2k_lens[gf2k->id];
297 303
298 init_input_dev(&gf2k->dev); 304 input_dev->name = gf2k_names[gf2k->id];
299 305 input_dev->phys = gf2k->phys;
300 gf2k->dev.private = gf2k; 306 input_dev->id.bustype = BUS_GAMEPORT;
301 gf2k->dev.open = gf2k_open; 307 input_dev->id.vendor = GAMEPORT_ID_VENDOR_GENIUS;
302 gf2k->dev.close = gf2k_close; 308 input_dev->id.product = gf2k->id;
303 gf2k->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 309 input_dev->id.version = 0x0100;
310 input_dev->cdev.dev = &gameport->dev;
311 input_dev->private = gf2k;
304 312
305 gf2k->dev.name = gf2k_names[gf2k->id]; 313 input_dev->open = gf2k_open;
306 gf2k->dev.phys = gf2k->phys; 314 input_dev->close = gf2k_close;
307 gf2k->dev.id.bustype = BUS_GAMEPORT; 315 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
308 gf2k->dev.id.vendor = GAMEPORT_ID_VENDOR_GENIUS;
309 gf2k->dev.id.product = gf2k->id;
310 gf2k->dev.id.version = 0x0100;
311 316
312 for (i = 0; i < gf2k_axes[gf2k->id]; i++) 317 for (i = 0; i < gf2k_axes[gf2k->id]; i++)
313 set_bit(gf2k_abs[i], gf2k->dev.absbit); 318 set_bit(gf2k_abs[i], input_dev->absbit);
314 319
315 for (i = 0; i < gf2k_hats[gf2k->id]; i++) { 320 for (i = 0; i < gf2k_hats[gf2k->id]; i++) {
316 set_bit(ABS_HAT0X + i, gf2k->dev.absbit); 321 set_bit(ABS_HAT0X + i, input_dev->absbit);
317 gf2k->dev.absmin[ABS_HAT0X + i] = -1; 322 input_dev->absmin[ABS_HAT0X + i] = -1;
318 gf2k->dev.absmax[ABS_HAT0X + i] = 1; 323 input_dev->absmax[ABS_HAT0X + i] = 1;
319 } 324 }
320 325
321 for (i = 0; i < gf2k_joys[gf2k->id]; i++) 326 for (i = 0; i < gf2k_joys[gf2k->id]; i++)
322 set_bit(gf2k_btn_joy[i], gf2k->dev.keybit); 327 set_bit(gf2k_btn_joy[i], input_dev->keybit);
323 328
324 for (i = 0; i < gf2k_pads[gf2k->id]; i++) 329 for (i = 0; i < gf2k_pads[gf2k->id]; i++)
325 set_bit(gf2k_btn_pad[i], gf2k->dev.keybit); 330 set_bit(gf2k_btn_pad[i], input_dev->keybit);
326 331
327 gf2k_read_packet(gameport, gf2k->length, data); 332 gf2k_read_packet(gameport, gf2k->length, data);
328 gf2k_read(gf2k, data); 333 gf2k_read(gf2k, data);
329 334
330 for (i = 0; i < gf2k_axes[gf2k->id]; i++) { 335 for (i = 0; i < gf2k_axes[gf2k->id]; i++) {
331 gf2k->dev.absmax[gf2k_abs[i]] = (i < 2) ? gf2k->dev.abs[gf2k_abs[i]] * 2 - 32 : 336 input_dev->absmax[gf2k_abs[i]] = (i < 2) ? input_dev->abs[gf2k_abs[i]] * 2 - 32 :
332 gf2k->dev.abs[gf2k_abs[0]] + gf2k->dev.abs[gf2k_abs[1]] - 32; 337 input_dev->abs[gf2k_abs[0]] + input_dev->abs[gf2k_abs[1]] - 32;
333 gf2k->dev.absmin[gf2k_abs[i]] = 32; 338 input_dev->absmin[gf2k_abs[i]] = 32;
334 gf2k->dev.absfuzz[gf2k_abs[i]] = 8; 339 input_dev->absfuzz[gf2k_abs[i]] = 8;
335 gf2k->dev.absflat[gf2k_abs[i]] = (i < 2) ? 24 : 0; 340 input_dev->absflat[gf2k_abs[i]] = (i < 2) ? 24 : 0;
336 } 341 }
337 342
338 input_register_device(&gf2k->dev); 343 input_register_device(gf2k->dev);
339 printk(KERN_INFO "input: %s on %s\n", gf2k_names[gf2k->id], gameport->phys);
340 344
341 return 0; 345 return 0;
342 346
343fail2: gameport_close(gameport); 347 fail2: gameport_close(gameport);
344fail1: gameport_set_drvdata(gameport, NULL); 348 fail1: gameport_set_drvdata(gameport, NULL);
349 input_free_device(input_dev);
345 kfree(gf2k); 350 kfree(gf2k);
346 return err; 351 return err;
347} 352}
@@ -350,7 +355,7 @@ static void gf2k_disconnect(struct gameport *gameport)
350{ 355{
351 struct gf2k *gf2k = gameport_get_drvdata(gameport); 356 struct gf2k *gf2k = gameport_get_drvdata(gameport);
352 357
353 input_unregister_device(&gf2k->dev); 358 input_unregister_device(gf2k->dev);
354 gameport_close(gameport); 359 gameport_close(gameport);
355 gameport_set_drvdata(gameport, NULL); 360 gameport_set_drvdata(gameport, NULL);
356 kfree(gf2k); 361 kfree(gf2k);
diff --git a/drivers/input/joystick/grip.c b/drivers/input/joystick/grip.c
index 9d3f910dd568..e206bb56e53c 100644
--- a/drivers/input/joystick/grip.c
+++ b/drivers/input/joystick/grip.c
@@ -55,7 +55,7 @@ MODULE_LICENSE("GPL");
55 55
56struct grip { 56struct grip {
57 struct gameport *gameport; 57 struct gameport *gameport;
58 struct input_dev dev[2]; 58 struct input_dev *dev[2];
59 unsigned char mode[2]; 59 unsigned char mode[2];
60 int reads; 60 int reads;
61 int bads; 61 int bads;
@@ -190,7 +190,7 @@ static void grip_poll(struct gameport *gameport)
190 190
191 for (i = 0; i < 2; i++) { 191 for (i = 0; i < 2; i++) {
192 192
193 dev = grip->dev + i; 193 dev = grip->dev[i];
194 grip->reads++; 194 grip->reads++;
195 195
196 switch (grip->mode[i]) { 196 switch (grip->mode[i]) {
@@ -297,6 +297,7 @@ static void grip_close(struct input_dev *dev)
297static int grip_connect(struct gameport *gameport, struct gameport_driver *drv) 297static int grip_connect(struct gameport *gameport, struct gameport_driver *drv)
298{ 298{
299 struct grip *grip; 299 struct grip *grip;
300 struct input_dev *input_dev;
300 unsigned int data[GRIP_LENGTH_XT]; 301 unsigned int data[GRIP_LENGTH_XT];
301 int i, j, t; 302 int i, j, t;
302 int err; 303 int err;
@@ -339,48 +340,56 @@ static int grip_connect(struct gameport *gameport, struct gameport_driver *drv)
339 gameport_set_poll_handler(gameport, grip_poll); 340 gameport_set_poll_handler(gameport, grip_poll);
340 gameport_set_poll_interval(gameport, 20); 341 gameport_set_poll_interval(gameport, 20);
341 342
342 for (i = 0; i < 2; i++) 343 for (i = 0; i < 2; i++) {
343 if (grip->mode[i]) { 344 if (!grip->mode[i])
345 continue;
344 346
345 sprintf(grip->phys[i], "%s/input%d", gameport->phys, i); 347 grip->dev[i] = input_dev = input_allocate_device();
348 if (!input_dev) {
349 err = -ENOMEM;
350 goto fail3;
351 }
346 352
347 grip->dev[i].private = grip; 353 sprintf(grip->phys[i], "%s/input%d", gameport->phys, i);
348 354
349 grip->dev[i].open = grip_open; 355 input_dev->name = grip_name[grip->mode[i]];
350 grip->dev[i].close = grip_close; 356 input_dev->phys = grip->phys[i];
357 input_dev->id.bustype = BUS_GAMEPORT;
358 input_dev->id.vendor = GAMEPORT_ID_VENDOR_GRAVIS;
359 input_dev->id.product = grip->mode[i];
360 input_dev->id.version = 0x0100;
361 input_dev->cdev.dev = &gameport->dev;
362 input_dev->private = grip;
351 363
352 grip->dev[i].name = grip_name[grip->mode[i]]; 364 input_dev->open = grip_open;
353 grip->dev[i].phys = grip->phys[i]; 365 input_dev->close = grip_close;
354 grip->dev[i].id.bustype = BUS_GAMEPORT;
355 grip->dev[i].id.vendor = GAMEPORT_ID_VENDOR_GRAVIS;
356 grip->dev[i].id.product = grip->mode[i];
357 grip->dev[i].id.version = 0x0100;
358 366
359 grip->dev[i].evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 367 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
360 368
361 for (j = 0; (t = grip_abs[grip->mode[i]][j]) >= 0; j++) { 369 for (j = 0; (t = grip_abs[grip->mode[i]][j]) >= 0; j++) {
362 370
363 if (j < grip_cen[grip->mode[i]]) 371 if (j < grip_cen[grip->mode[i]])
364 input_set_abs_params(&grip->dev[i], t, 14, 52, 1, 2); 372 input_set_abs_params(input_dev, t, 14, 52, 1, 2);
365 else if (j < grip_anx[grip->mode[i]]) 373 else if (j < grip_anx[grip->mode[i]])
366 input_set_abs_params(&grip->dev[i], t, 3, 57, 1, 0); 374 input_set_abs_params(input_dev, t, 3, 57, 1, 0);
367 else 375 else
368 input_set_abs_params(&grip->dev[i], t, -1, 1, 0, 0); 376 input_set_abs_params(input_dev, t, -1, 1, 0, 0);
369 } 377 }
370 378
371 for (j = 0; (t = grip_btn[grip->mode[i]][j]) >= 0; j++) 379 for (j = 0; (t = grip_btn[grip->mode[i]][j]) >= 0; j++)
372 if (t > 0) 380 if (t > 0)
373 set_bit(t, grip->dev[i].keybit); 381 set_bit(t, input_dev->keybit);
374 382
375 printk(KERN_INFO "input: %s on %s\n", 383 input_register_device(grip->dev[i]);
376 grip_name[grip->mode[i]], gameport->phys); 384 }
377 input_register_device(grip->dev + i);
378 }
379 385
380 return 0; 386 return 0;
381 387
382fail2: gameport_close(gameport); 388 fail3: for (i = 0; i < 2; i++)
383fail1: gameport_set_drvdata(gameport, NULL); 389 if (grip->dev[i])
390 input_unregister_device(grip->dev[i]);
391 fail2: gameport_close(gameport);
392 fail1: gameport_set_drvdata(gameport, NULL);
384 kfree(grip); 393 kfree(grip);
385 return err; 394 return err;
386} 395}
@@ -391,8 +400,8 @@ static void grip_disconnect(struct gameport *gameport)
391 int i; 400 int i;
392 401
393 for (i = 0; i < 2; i++) 402 for (i = 0; i < 2; i++)
394 if (grip->mode[i]) 403 if (grip->dev[i])
395 input_unregister_device(grip->dev + i); 404 input_unregister_device(grip->dev[i]);
396 gameport_close(gameport); 405 gameport_close(gameport);
397 gameport_set_drvdata(gameport, NULL); 406 gameport_set_drvdata(gameport, NULL);
398 kfree(grip); 407 kfree(grip);
diff --git a/drivers/input/joystick/grip_mp.c b/drivers/input/joystick/grip_mp.c
index da17eee6f574..a0ba93ccac72 100644
--- a/drivers/input/joystick/grip_mp.c
+++ b/drivers/input/joystick/grip_mp.c
@@ -32,23 +32,37 @@ MODULE_LICENSE("GPL");
32#define dbg(format, arg...) do {} while (0) 32#define dbg(format, arg...) do {} while (0)
33#endif 33#endif
34 34
35#define GRIP_MAX_PORTS 4
35/* 36/*
36 * Grip multiport state 37 * Grip multiport state
37 */ 38 */
38 39
40struct grip_port {
41 struct input_dev *dev;
42 int mode;
43 int registered;
44
45 /* individual gamepad states */
46 int buttons;
47 int xaxes;
48 int yaxes;
49 int dirty; /* has the state been updated? */
50};
51
39struct grip_mp { 52struct grip_mp {
40 struct gameport *gameport; 53 struct gameport *gameport;
41 struct input_dev dev[4]; 54 struct grip_port *port[GRIP_MAX_PORTS];
42 int mode[4]; 55// struct input_dev *dev[4];
43 int registered[4]; 56// int mode[4];
57// int registered[4];
44 int reads; 58 int reads;
45 int bads; 59 int bads;
46 60
47 /* individual gamepad states */ 61 /* individual gamepad states */
48 int buttons[4]; 62// int buttons[4];
49 int xaxes[4]; 63// int xaxes[4];
50 int yaxes[4]; 64// int yaxes[4];
51 int dirty[4]; /* has the state been updated? */ 65// int dirty[4]; /* has the state been updated? */
52}; 66};
53 67
54/* 68/*
@@ -85,16 +99,16 @@ struct grip_mp {
85#define GRIP_MODE_GP 2 99#define GRIP_MODE_GP 2
86#define GRIP_MODE_C64 3 100#define GRIP_MODE_C64 3
87 101
88static int grip_btn_gp[] = { BTN_TR, BTN_TL, BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, -1 }; 102static const int grip_btn_gp[] = { BTN_TR, BTN_TL, BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, -1 };
89static int grip_btn_c64[] = { BTN_JOYSTICK, -1 }; 103static const int grip_btn_c64[] = { BTN_JOYSTICK, -1 };
90 104
91static int grip_abs_gp[] = { ABS_X, ABS_Y, -1 }; 105static const int grip_abs_gp[] = { ABS_X, ABS_Y, -1 };
92static int grip_abs_c64[] = { ABS_X, ABS_Y, -1 }; 106static const int grip_abs_c64[] = { ABS_X, ABS_Y, -1 };
93 107
94static int *grip_abs[] = { NULL, NULL, grip_abs_gp, grip_abs_c64 }; 108static const int *grip_abs[] = { NULL, NULL, grip_abs_gp, grip_abs_c64 };
95static int *grip_btn[] = { NULL, NULL, grip_btn_gp, grip_btn_c64 }; 109static const int *grip_btn[] = { NULL, NULL, grip_btn_gp, grip_btn_c64 };
96 110
97static char *grip_name[] = { NULL, NULL, "Gravis Grip Pad", "Commodore 64 Joystick" }; 111static const char *grip_name[] = { NULL, NULL, "Gravis Grip Pad", "Commodore 64 Joystick" };
98 112
99static const int init_seq[] = { 113static const int init_seq[] = {
100 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 114 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1,
@@ -104,9 +118,9 @@ static const int init_seq[] = {
104 118
105/* Maps multiport directional values to X,Y axis values (each axis encoded in 3 bits) */ 119/* Maps multiport directional values to X,Y axis values (each axis encoded in 3 bits) */
106 120
107static int axis_map[] = { 5, 9, 1, 5, 6, 10, 2, 6, 4, 8, 0, 4, 5, 9, 1, 5 }; 121static const int axis_map[] = { 5, 9, 1, 5, 6, 10, 2, 6, 4, 8, 0, 4, 5, 9, 1, 5 };
108 122
109static void register_slot(int i, struct grip_mp *grip); 123static int register_slot(int i, struct grip_mp *grip);
110 124
111/* 125/*
112 * Returns whether an odd or even number of bits are on in pkt. 126 * Returns whether an odd or even number of bits are on in pkt.
@@ -353,9 +367,10 @@ static int dig_mode_start(struct gameport *gameport, u32 *packet)
353 367
354static int get_and_decode_packet(struct grip_mp *grip, int flags) 368static int get_and_decode_packet(struct grip_mp *grip, int flags)
355{ 369{
370 struct grip_port *port;
356 u32 packet; 371 u32 packet;
357 int joytype = 0; 372 int joytype = 0;
358 int slot = 0; 373 int slot;
359 374
360 /* Get a packet and check for validity */ 375 /* Get a packet and check for validity */
361 376
@@ -377,6 +392,8 @@ static int get_and_decode_packet(struct grip_mp *grip, int flags)
377 if ((slot < 0) || (slot > 3)) 392 if ((slot < 0) || (slot > 3))
378 return flags; 393 return flags;
379 394
395 port = grip->port[slot];
396
380 /* 397 /*
381 * Handle "reset" packets, which occur at startup, and when gamepads 398 * Handle "reset" packets, which occur at startup, and when gamepads
382 * are removed or plugged in. May contain configuration of a new gamepad. 399 * are removed or plugged in. May contain configuration of a new gamepad.
@@ -385,14 +402,14 @@ static int get_and_decode_packet(struct grip_mp *grip, int flags)
385 joytype = (packet >> 16) & 0x1f; 402 joytype = (packet >> 16) & 0x1f;
386 if (!joytype) { 403 if (!joytype) {
387 404
388 if (grip->registered[slot]) { 405 if (port->registered) {
389 printk(KERN_INFO "grip_mp: removing %s, slot %d\n", 406 printk(KERN_INFO "grip_mp: removing %s, slot %d\n",
390 grip_name[grip->mode[slot]], slot); 407 grip_name[port->mode], slot);
391 input_unregister_device(grip->dev + slot); 408 input_unregister_device(port->dev);
392 grip->registered[slot] = 0; 409 port->registered = 0;
393 } 410 }
394 dbg("Reset: grip multiport slot %d\n", slot); 411 dbg("Reset: grip multiport slot %d\n", slot);
395 grip->mode[slot] = GRIP_MODE_RESET; 412 port->mode = GRIP_MODE_RESET;
396 flags |= IO_SLOT_CHANGE; 413 flags |= IO_SLOT_CHANGE;
397 return flags; 414 return flags;
398 } 415 }
@@ -402,17 +419,17 @@ static int get_and_decode_packet(struct grip_mp *grip, int flags)
402 if (joytype == 0x1f) { 419 if (joytype == 0x1f) {
403 420
404 int dir = (packet >> 8) & 0xf; /* eight way directional value */ 421 int dir = (packet >> 8) & 0xf; /* eight way directional value */
405 grip->buttons[slot] = (~packet) & 0xff; 422 port->buttons = (~packet) & 0xff;
406 grip->yaxes[slot] = ((axis_map[dir] >> 2) & 3) - 1; 423 port->yaxes = ((axis_map[dir] >> 2) & 3) - 1;
407 grip->xaxes[slot] = (axis_map[dir] & 3) - 1; 424 port->xaxes = (axis_map[dir] & 3) - 1;
408 grip->dirty[slot] = 1; 425 port->dirty = 1;
409 426
410 if (grip->mode[slot] == GRIP_MODE_RESET) 427 if (port->mode == GRIP_MODE_RESET)
411 flags |= IO_SLOT_CHANGE; 428 flags |= IO_SLOT_CHANGE;
412 429
413 grip->mode[slot] = GRIP_MODE_GP; 430 port->mode = GRIP_MODE_GP;
414 431
415 if (!grip->registered[slot]) { 432 if (!port->registered) {
416 dbg("New Grip pad in multiport slot %d.\n", slot); 433 dbg("New Grip pad in multiport slot %d.\n", slot);
417 register_slot(slot, grip); 434 register_slot(slot, grip);
418 } 435 }
@@ -445,9 +462,9 @@ static int slots_valid(struct grip_mp *grip)
445 return 0; 462 return 0;
446 463
447 for (slot = 0; slot < 4; slot++) { 464 for (slot = 0; slot < 4; slot++) {
448 if (grip->mode[slot] == GRIP_MODE_RESET) 465 if (grip->port[slot]->mode == GRIP_MODE_RESET)
449 invalid = 1; 466 invalid = 1;
450 if (grip->mode[slot] != GRIP_MODE_NONE) 467 if (grip->port[slot]->mode != GRIP_MODE_NONE)
451 active = 1; 468 active = 1;
452 } 469 }
453 470
@@ -484,7 +501,7 @@ static int multiport_init(struct grip_mp *grip)
484 501
485 /* Get packets, store multiport state, and check state's validity */ 502 /* Get packets, store multiport state, and check state's validity */
486 for (tries = 0; tries < 4096; tries++) { 503 for (tries = 0; tries < 4096; tries++) {
487 if ( slots_valid(grip) ) { 504 if (slots_valid(grip)) {
488 initialized = 1; 505 initialized = 1;
489 break; 506 break;
490 } 507 }
@@ -499,24 +516,24 @@ static int multiport_init(struct grip_mp *grip)
499 516
500static void report_slot(struct grip_mp *grip, int slot) 517static void report_slot(struct grip_mp *grip, int slot)
501{ 518{
502 struct input_dev *dev = &(grip->dev[slot]); 519 struct grip_port *port = grip->port[slot];
503 int i, buttons = grip->buttons[slot]; 520 int i;
504 521
505 /* Store button states with linux input driver */ 522 /* Store button states with linux input driver */
506 523
507 for (i = 0; i < 8; i++) 524 for (i = 0; i < 8; i++)
508 input_report_key(dev, grip_btn_gp[i], (buttons >> i) & 1); 525 input_report_key(port->dev, grip_btn_gp[i], (port->buttons >> i) & 1);
509 526
510 /* Store axis states with linux driver */ 527 /* Store axis states with linux driver */
511 528
512 input_report_abs(dev, ABS_X, grip->xaxes[slot]); 529 input_report_abs(port->dev, ABS_X, port->xaxes);
513 input_report_abs(dev, ABS_Y, grip->yaxes[slot]); 530 input_report_abs(port->dev, ABS_Y, port->yaxes);
514 531
515 /* Tell the receiver of the events to process them */ 532 /* Tell the receiver of the events to process them */
516 533
517 input_sync(dev); 534 input_sync(port->dev);
518 535
519 grip->dirty[slot] = 0; 536 port->dirty = 0;
520} 537}
521 538
522/* 539/*
@@ -540,7 +557,7 @@ static void grip_poll(struct gameport *gameport)
540 } 557 }
541 558
542 for (i = 0; i < 4; i++) 559 for (i = 0; i < 4; i++)
543 if (grip->dirty[i]) 560 if (grip->port[i]->dirty)
544 report_slot(grip, i); 561 report_slot(grip, i);
545} 562}
546 563
@@ -571,35 +588,43 @@ static void grip_close(struct input_dev *dev)
571 * Tell the linux input layer about a newly plugged-in gamepad. 588 * Tell the linux input layer about a newly plugged-in gamepad.
572 */ 589 */
573 590
574static void register_slot(int slot, struct grip_mp *grip) 591static int register_slot(int slot, struct grip_mp *grip)
575{ 592{
593 struct grip_port *port = grip->port[slot];
594 struct input_dev *input_dev;
576 int j, t; 595 int j, t;
577 596
578 grip->dev[slot].private = grip; 597 port->dev = input_dev = input_allocate_device();
579 grip->dev[slot].open = grip_open; 598 if (!input_dev)
580 grip->dev[slot].close = grip_close; 599 return -ENOMEM;
581 grip->dev[slot].name = grip_name[grip->mode[slot]]; 600
582 grip->dev[slot].id.bustype = BUS_GAMEPORT; 601 input_dev->name = grip_name[port->mode];
583 grip->dev[slot].id.vendor = GAMEPORT_ID_VENDOR_GRAVIS; 602 input_dev->id.bustype = BUS_GAMEPORT;
584 grip->dev[slot].id.product = 0x0100 + grip->mode[slot]; 603 input_dev->id.vendor = GAMEPORT_ID_VENDOR_GRAVIS;
585 grip->dev[slot].id.version = 0x0100; 604 input_dev->id.product = 0x0100 + port->mode;
586 grip->dev[slot].evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 605 input_dev->id.version = 0x0100;
606 input_dev->cdev.dev = &grip->gameport->dev;
607 input_dev->private = grip;
608
609 input_dev->open = grip_open;
610 input_dev->close = grip_close;
587 611
588 for (j = 0; (t = grip_abs[grip->mode[slot]][j]) >= 0; j++) 612 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
589 input_set_abs_params(&grip->dev[slot], t, -1, 1, 0, 0);
590 613
591 for (j = 0; (t = grip_btn[grip->mode[slot]][j]) >= 0; j++) 614 for (j = 0; (t = grip_abs[port->mode][j]) >= 0; j++)
615 input_set_abs_params(input_dev, t, -1, 1, 0, 0);
616
617 for (j = 0; (t = grip_btn[port->mode][j]) >= 0; j++)
592 if (t > 0) 618 if (t > 0)
593 set_bit(t, grip->dev[slot].keybit); 619 set_bit(t, input_dev->keybit);
594 620
595 input_register_device(grip->dev + slot); 621 input_register_device(port->dev);
596 grip->registered[slot] = 1; 622 port->registered = 1;
597 623
598 if (grip->dirty[slot]) /* report initial state, if any */ 624 if (port->dirty) /* report initial state, if any */
599 report_slot(grip, slot); 625 report_slot(grip, slot);
600 626
601 printk(KERN_INFO "grip_mp: added %s, slot %d\n", 627 return 0;
602 grip_name[grip->mode[slot]], slot);
603} 628}
604 629
605static int grip_connect(struct gameport *gameport, struct gameport_driver *drv) 630static int grip_connect(struct gameport *gameport, struct gameport_driver *drv)
@@ -626,7 +651,7 @@ static int grip_connect(struct gameport *gameport, struct gameport_driver *drv)
626 goto fail2; 651 goto fail2;
627 } 652 }
628 653
629 if (!grip->mode[0] && !grip->mode[1] && !grip->mode[2] && !grip->mode[3]) { 654 if (!grip->port[0]->mode && !grip->port[1]->mode && !grip->port[2]->mode && !grip->port[3]->mode) {
630 /* nothing plugged in */ 655 /* nothing plugged in */
631 err = -ENODEV; 656 err = -ENODEV;
632 goto fail2; 657 goto fail2;
@@ -646,8 +671,8 @@ static void grip_disconnect(struct gameport *gameport)
646 int i; 671 int i;
647 672
648 for (i = 0; i < 4; i++) 673 for (i = 0; i < 4; i++)
649 if (grip->registered[i]) 674 if (grip->port[i]->registered)
650 input_unregister_device(grip->dev + i); 675 input_unregister_device(grip->port[i]->dev);
651 gameport_close(gameport); 676 gameport_close(gameport);
652 gameport_set_drvdata(gameport, NULL); 677 gameport_set_drvdata(gameport, NULL);
653 kfree(grip); 678 kfree(grip);
diff --git a/drivers/input/joystick/guillemot.c b/drivers/input/joystick/guillemot.c
index 6a70ec429f06..c528473c09d8 100644
--- a/drivers/input/joystick/guillemot.c
+++ b/drivers/input/joystick/guillemot.c
@@ -67,7 +67,7 @@ struct guillemot_type {
67 67
68struct guillemot { 68struct guillemot {
69 struct gameport *gameport; 69 struct gameport *gameport;
70 struct input_dev dev; 70 struct input_dev *dev;
71 int bads; 71 int bads;
72 int reads; 72 int reads;
73 struct guillemot_type *type; 73 struct guillemot_type *type;
@@ -123,7 +123,7 @@ static int guillemot_read_packet(struct gameport *gameport, u8 *data)
123static void guillemot_poll(struct gameport *gameport) 123static void guillemot_poll(struct gameport *gameport)
124{ 124{
125 struct guillemot *guillemot = gameport_get_drvdata(gameport); 125 struct guillemot *guillemot = gameport_get_drvdata(gameport);
126 struct input_dev *dev = &guillemot->dev; 126 struct input_dev *dev = guillemot->dev;
127 u8 data[GUILLEMOT_MAX_LENGTH]; 127 u8 data[GUILLEMOT_MAX_LENGTH];
128 int i; 128 int i;
129 129
@@ -179,14 +179,20 @@ static void guillemot_close(struct input_dev *dev)
179static int guillemot_connect(struct gameport *gameport, struct gameport_driver *drv) 179static int guillemot_connect(struct gameport *gameport, struct gameport_driver *drv)
180{ 180{
181 struct guillemot *guillemot; 181 struct guillemot *guillemot;
182 struct input_dev *input_dev;
182 u8 data[GUILLEMOT_MAX_LENGTH]; 183 u8 data[GUILLEMOT_MAX_LENGTH];
183 int i, t; 184 int i, t;
184 int err; 185 int err;
185 186
186 if (!(guillemot = kzalloc(sizeof(struct guillemot), GFP_KERNEL))) 187 guillemot = kzalloc(sizeof(struct guillemot), GFP_KERNEL);
187 return -ENOMEM; 188 input_dev = input_allocate_device();
189 if (!guillemot || !input_dev) {
190 err = -ENOMEM;
191 goto fail1;
192 }
188 193
189 guillemot->gameport = gameport; 194 guillemot->gameport = gameport;
195 guillemot->dev = input_dev;
190 196
191 gameport_set_drvdata(gameport, guillemot); 197 gameport_set_drvdata(gameport, guillemot);
192 198
@@ -216,41 +222,40 @@ static int guillemot_connect(struct gameport *gameport, struct gameport_driver *
216 gameport_set_poll_interval(gameport, 20); 222 gameport_set_poll_interval(gameport, 20);
217 223
218 sprintf(guillemot->phys, "%s/input0", gameport->phys); 224 sprintf(guillemot->phys, "%s/input0", gameport->phys);
219
220 guillemot->type = guillemot_type + i; 225 guillemot->type = guillemot_type + i;
221 226
222 guillemot->dev.private = guillemot; 227 input_dev->name = guillemot_type[i].name;
223 guillemot->dev.open = guillemot_open; 228 input_dev->phys = guillemot->phys;
224 guillemot->dev.close = guillemot_close; 229 input_dev->id.bustype = BUS_GAMEPORT;
230 input_dev->id.vendor = GAMEPORT_ID_VENDOR_GUILLEMOT;
231 input_dev->id.product = guillemot_type[i].id;
232 input_dev->id.version = (int)data[14] << 8 | data[15];
233 input_dev->cdev.dev = &gameport->dev;
234 input_dev->private = guillemot;
225 235
226 guillemot->dev.name = guillemot_type[i].name; 236 input_dev->open = guillemot_open;
227 guillemot->dev.phys = guillemot->phys; 237 input_dev->close = guillemot_close;
228 guillemot->dev.id.bustype = BUS_GAMEPORT;
229 guillemot->dev.id.vendor = GAMEPORT_ID_VENDOR_GUILLEMOT;
230 guillemot->dev.id.product = guillemot_type[i].id;
231 guillemot->dev.id.version = (int)data[14] << 8 | data[15];
232 238
233 guillemot->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 239 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
234 240
235 for (i = 0; (t = guillemot->type->abs[i]) >= 0; i++) 241 for (i = 0; (t = guillemot->type->abs[i]) >= 0; i++)
236 input_set_abs_params(&guillemot->dev, t, 0, 255, 0, 0); 242 input_set_abs_params(input_dev, t, 0, 255, 0, 0);
237 243
238 if (guillemot->type->hat) { 244 if (guillemot->type->hat) {
239 input_set_abs_params(&guillemot->dev, ABS_HAT0X, -1, 1, 0, 0); 245 input_set_abs_params(input_dev, ABS_HAT0X, -1, 1, 0, 0);
240 input_set_abs_params(&guillemot->dev, ABS_HAT0Y, -1, 1, 0, 0); 246 input_set_abs_params(input_dev, ABS_HAT0Y, -1, 1, 0, 0);
241 } 247 }
242 248
243 for (i = 0; (t = guillemot->type->btn[i]) >= 0; i++) 249 for (i = 0; (t = guillemot->type->btn[i]) >= 0; i++)
244 set_bit(t, guillemot->dev.keybit); 250 set_bit(t, input_dev->keybit);
245 251
246 input_register_device(&guillemot->dev); 252 input_register_device(guillemot->dev);
247 printk(KERN_INFO "input: %s ver %d.%02d on %s\n",
248 guillemot->type->name, data[14], data[15], gameport->phys);
249 253
250 return 0; 254 return 0;
251 255
252fail2: gameport_close(gameport); 256fail2: gameport_close(gameport);
253fail1: gameport_set_drvdata(gameport, NULL); 257fail1: gameport_set_drvdata(gameport, NULL);
258 input_free_device(input_dev);
254 kfree(guillemot); 259 kfree(guillemot);
255 return err; 260 return err;
256} 261}
@@ -260,7 +265,7 @@ static void guillemot_disconnect(struct gameport *gameport)
260 struct guillemot *guillemot = gameport_get_drvdata(gameport); 265 struct guillemot *guillemot = gameport_get_drvdata(gameport);
261 266
262 printk(KERN_INFO "guillemot.c: Failed %d reads out of %d on %s\n", guillemot->reads, guillemot->bads, guillemot->phys); 267 printk(KERN_INFO "guillemot.c: Failed %d reads out of %d on %s\n", guillemot->reads, guillemot->bads, guillemot->phys);
263 input_unregister_device(&guillemot->dev); 268 input_unregister_device(guillemot->dev);
264 gameport_close(gameport); 269 gameport_close(gameport);
265 kfree(guillemot); 270 kfree(guillemot);
266} 271}
diff --git a/drivers/input/joystick/iforce/iforce-main.c b/drivers/input/joystick/iforce/iforce-main.c
index e31b7b93fde2..64b9c31c47fc 100644
--- a/drivers/input/joystick/iforce/iforce-main.c
+++ b/drivers/input/joystick/iforce/iforce-main.c
@@ -144,7 +144,7 @@ static int iforce_upload_effect(struct input_dev *dev, struct ff_effect *effect)
144 int is_update; 144 int is_update;
145 145
146/* Check this effect type is supported by this device */ 146/* Check this effect type is supported by this device */
147 if (!test_bit(effect->type, iforce->dev.ffbit)) 147 if (!test_bit(effect->type, iforce->dev->ffbit))
148 return -EINVAL; 148 return -EINVAL;
149 149
150/* 150/*
@@ -152,30 +152,31 @@ static int iforce_upload_effect(struct input_dev *dev, struct ff_effect *effect)
152 */ 152 */
153 if (effect->id == -1) { 153 if (effect->id == -1) {
154 154
155 for (id=0; id < FF_EFFECTS_MAX; ++id) 155 for (id = 0; id < FF_EFFECTS_MAX; ++id)
156 if (!test_and_set_bit(FF_CORE_IS_USED, iforce->core_effects[id].flags)) break; 156 if (!test_and_set_bit(FF_CORE_IS_USED, iforce->core_effects[id].flags))
157 break;
157 158
158 if ( id == FF_EFFECTS_MAX || id >= iforce->dev.ff_effects_max) 159 if (id == FF_EFFECTS_MAX || id >= iforce->dev->ff_effects_max)
159 return -ENOMEM; 160 return -ENOMEM;
160 161
161 effect->id = id; 162 effect->id = id;
162 iforce->core_effects[id].owner = current->pid; 163 iforce->core_effects[id].owner = current->pid;
163 iforce->core_effects[id].flags[0] = (1<<FF_CORE_IS_USED); /* Only IS_USED bit must be set */ 164 iforce->core_effects[id].flags[0] = (1 << FF_CORE_IS_USED); /* Only IS_USED bit must be set */
164 165
165 is_update = FALSE; 166 is_update = FALSE;
166 } 167 }
167 else { 168 else {
168 /* We want to update an effect */ 169 /* We want to update an effect */
169 if (!CHECK_OWNERSHIP(effect->id, iforce)) return -EACCES; 170 if (!CHECK_OWNERSHIP(effect->id, iforce))
171 return -EACCES;
170 172
171 /* Parameter type cannot be updated */ 173 /* Parameter type cannot be updated */
172 if (effect->type != iforce->core_effects[effect->id].effect.type) 174 if (effect->type != iforce->core_effects[effect->id].effect.type)
173 return -EINVAL; 175 return -EINVAL;
174 176
175 /* Check the effect is not already being updated */ 177 /* Check the effect is not already being updated */
176 if (test_bit(FF_CORE_UPDATE, iforce->core_effects[effect->id].flags)) { 178 if (test_bit(FF_CORE_UPDATE, iforce->core_effects[effect->id].flags))
177 return -EAGAIN; 179 return -EAGAIN;
178 }
179 180
180 is_update = TRUE; 181 is_update = TRUE;
181 } 182 }
@@ -339,15 +340,19 @@ void iforce_delete_device(struct iforce *iforce)
339 340
340int iforce_init_device(struct iforce *iforce) 341int iforce_init_device(struct iforce *iforce)
341{ 342{
343 struct input_dev *input_dev;
342 unsigned char c[] = "CEOV"; 344 unsigned char c[] = "CEOV";
343 int i; 345 int i;
344 346
347 input_dev = input_allocate_device();
348 if (input_dev)
349 return -ENOMEM;
350
345 init_waitqueue_head(&iforce->wait); 351 init_waitqueue_head(&iforce->wait);
346 spin_lock_init(&iforce->xmit_lock); 352 spin_lock_init(&iforce->xmit_lock);
347 init_MUTEX(&iforce->mem_mutex); 353 init_MUTEX(&iforce->mem_mutex);
348 iforce->xmit.buf = iforce->xmit_data; 354 iforce->xmit.buf = iforce->xmit_data;
349 355 iforce->dev = input_dev;
350 iforce->dev.ff_effects_max = 10;
351 356
352/* 357/*
353 * Input device fields. 358 * Input device fields.
@@ -356,26 +361,27 @@ int iforce_init_device(struct iforce *iforce)
356 switch (iforce->bus) { 361 switch (iforce->bus) {
357#ifdef CONFIG_JOYSTICK_IFORCE_USB 362#ifdef CONFIG_JOYSTICK_IFORCE_USB
358 case IFORCE_USB: 363 case IFORCE_USB:
359 iforce->dev.id.bustype = BUS_USB; 364 input_dev->id.bustype = BUS_USB;
360 iforce->dev.dev = &iforce->usbdev->dev; 365 input_dev->cdev.dev = &iforce->usbdev->dev;
361 break; 366 break;
362#endif 367#endif
363#ifdef CONFIG_JOYSTICK_IFORCE_232 368#ifdef CONFIG_JOYSTICK_IFORCE_232
364 case IFORCE_232: 369 case IFORCE_232:
365 iforce->dev.id.bustype = BUS_RS232; 370 input_dev->id.bustype = BUS_RS232;
366 iforce->dev.dev = &iforce->serio->dev; 371 input_dev->cdev.dev = &iforce->serio->dev;
367 break; 372 break;
368#endif 373#endif
369 } 374 }
370 375
371 iforce->dev.private = iforce; 376 input_dev->private = iforce;
372 iforce->dev.name = "Unknown I-Force device"; 377 input_dev->name = "Unknown I-Force device";
373 iforce->dev.open = iforce_open; 378 input_dev->open = iforce_open;
374 iforce->dev.close = iforce_release; 379 input_dev->close = iforce_release;
375 iforce->dev.flush = iforce_flush; 380 input_dev->flush = iforce_flush;
376 iforce->dev.event = iforce_input_event; 381 input_dev->event = iforce_input_event;
377 iforce->dev.upload_effect = iforce_upload_effect; 382 input_dev->upload_effect = iforce_upload_effect;
378 iforce->dev.erase_effect = iforce_erase_effect; 383 input_dev->erase_effect = iforce_erase_effect;
384 input_dev->ff_effects_max = 10;
379 385
380/* 386/*
381 * On-device memory allocation. 387 * On-device memory allocation.
@@ -399,7 +405,8 @@ int iforce_init_device(struct iforce *iforce)
399 405
400 if (i == 20) { /* 5 seconds */ 406 if (i == 20) { /* 5 seconds */
401 printk(KERN_ERR "iforce-main.c: Timeout waiting for response from device.\n"); 407 printk(KERN_ERR "iforce-main.c: Timeout waiting for response from device.\n");
402 return -1; 408 input_free_device(input_dev);
409 return -ENODEV;
403 } 410 }
404 411
405/* 412/*
@@ -407,12 +414,12 @@ int iforce_init_device(struct iforce *iforce)
407 */ 414 */
408 415
409 if (!iforce_get_id_packet(iforce, "M")) 416 if (!iforce_get_id_packet(iforce, "M"))
410 iforce->dev.id.vendor = (iforce->edata[2] << 8) | iforce->edata[1]; 417 input_dev->id.vendor = (iforce->edata[2] << 8) | iforce->edata[1];
411 else 418 else
412 printk(KERN_WARNING "iforce-main.c: Device does not respond to id packet M\n"); 419 printk(KERN_WARNING "iforce-main.c: Device does not respond to id packet M\n");
413 420
414 if (!iforce_get_id_packet(iforce, "P")) 421 if (!iforce_get_id_packet(iforce, "P"))
415 iforce->dev.id.product = (iforce->edata[2] << 8) | iforce->edata[1]; 422 input_dev->id.product = (iforce->edata[2] << 8) | iforce->edata[1];
416 else 423 else
417 printk(KERN_WARNING "iforce-main.c: Device does not respond to id packet P\n"); 424 printk(KERN_WARNING "iforce-main.c: Device does not respond to id packet P\n");
418 425
@@ -422,15 +429,15 @@ int iforce_init_device(struct iforce *iforce)
422 printk(KERN_WARNING "iforce-main.c: Device does not respond to id packet B\n"); 429 printk(KERN_WARNING "iforce-main.c: Device does not respond to id packet B\n");
423 430
424 if (!iforce_get_id_packet(iforce, "N")) 431 if (!iforce_get_id_packet(iforce, "N"))
425 iforce->dev.ff_effects_max = iforce->edata[1]; 432 iforce->dev->ff_effects_max = iforce->edata[1];
426 else 433 else
427 printk(KERN_WARNING "iforce-main.c: Device does not respond to id packet N\n"); 434 printk(KERN_WARNING "iforce-main.c: Device does not respond to id packet N\n");
428 435
429 /* Check if the device can store more effects than the driver can really handle */ 436 /* Check if the device can store more effects than the driver can really handle */
430 if (iforce->dev.ff_effects_max > FF_EFFECTS_MAX) { 437 if (iforce->dev->ff_effects_max > FF_EFFECTS_MAX) {
431 printk(KERN_WARNING "input??: Device can handle %d effects, but N_EFFECTS_MAX is set to %d in iforce.h\n", 438 printk(KERN_WARNING "input??: Device can handle %d effects, but N_EFFECTS_MAX is set to %d in iforce.h\n",
432 iforce->dev.ff_effects_max, FF_EFFECTS_MAX); 439 iforce->dev->ff_effects_max, FF_EFFECTS_MAX);
433 iforce->dev.ff_effects_max = FF_EFFECTS_MAX; 440 iforce->dev->ff_effects_max = FF_EFFECTS_MAX;
434 } 441 }
435 442
436/* 443/*
@@ -453,29 +460,28 @@ int iforce_init_device(struct iforce *iforce)
453 */ 460 */
454 461
455 for (i = 0; iforce_device[i].idvendor; i++) 462 for (i = 0; iforce_device[i].idvendor; i++)
456 if (iforce_device[i].idvendor == iforce->dev.id.vendor && 463 if (iforce_device[i].idvendor == input_dev->id.vendor &&
457 iforce_device[i].idproduct == iforce->dev.id.product) 464 iforce_device[i].idproduct == input_dev->id.product)
458 break; 465 break;
459 466
460 iforce->type = iforce_device + i; 467 iforce->type = iforce_device + i;
461 iforce->dev.name = iforce->type->name; 468 input_dev->name = iforce->type->name;
462 469
463/* 470/*
464 * Set input device bitfields and ranges. 471 * Set input device bitfields and ranges.
465 */ 472 */
466 473
467 iforce->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_FF) | BIT(EV_FF_STATUS); 474 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_FF) | BIT(EV_FF_STATUS);
468 475
469 for (i = 0; iforce->type->btn[i] >= 0; i++) { 476 for (i = 0; iforce->type->btn[i] >= 0; i++) {
470 signed short t = iforce->type->btn[i]; 477 signed short t = iforce->type->btn[i];
471 set_bit(t, iforce->dev.keybit); 478 set_bit(t, input_dev->keybit);
472 } 479 }
473 set_bit(BTN_DEAD, iforce->dev.keybit); 480 set_bit(BTN_DEAD, input_dev->keybit);
474 481
475 for (i = 0; iforce->type->abs[i] >= 0; i++) { 482 for (i = 0; iforce->type->abs[i] >= 0; i++) {
476 483
477 signed short t = iforce->type->abs[i]; 484 signed short t = iforce->type->abs[i];
478 set_bit(t, iforce->dev.absbit);
479 485
480 switch (t) { 486 switch (t) {
481 487
@@ -483,52 +489,42 @@ int iforce_init_device(struct iforce *iforce)
483 case ABS_Y: 489 case ABS_Y:
484 case ABS_WHEEL: 490 case ABS_WHEEL:
485 491
486 iforce->dev.absmax[t] = 1920; 492 input_set_abs_params(input_dev, t, -1920, 1920, 16, 128);
487 iforce->dev.absmin[t] = -1920; 493 set_bit(t, input_dev->ffbit);
488 iforce->dev.absflat[t] = 128;
489 iforce->dev.absfuzz[t] = 16;
490
491 set_bit(t, iforce->dev.ffbit);
492 break; 494 break;
493 495
494 case ABS_THROTTLE: 496 case ABS_THROTTLE:
495 case ABS_GAS: 497 case ABS_GAS:
496 case ABS_BRAKE: 498 case ABS_BRAKE:
497 499
498 iforce->dev.absmax[t] = 255; 500 input_set_abs_params(input_dev, t, 0, 255, 0, 0);
499 iforce->dev.absmin[t] = 0;
500 break; 501 break;
501 502
502 case ABS_RUDDER: 503 case ABS_RUDDER:
503 504
504 iforce->dev.absmax[t] = 127; 505 input_set_abs_params(input_dev, t, -128, 127, 0, 0);
505 iforce->dev.absmin[t] = -128;
506 break; 506 break;
507 507
508 case ABS_HAT0X: 508 case ABS_HAT0X:
509 case ABS_HAT0Y: 509 case ABS_HAT0Y:
510 case ABS_HAT1X: 510 case ABS_HAT1X:
511 case ABS_HAT1Y: 511 case ABS_HAT1Y:
512 iforce->dev.absmax[t] = 1; 512
513 iforce->dev.absmin[t] = -1; 513 input_set_abs_params(input_dev, t, -1, 1, 0, 0);
514 break; 514 break;
515 } 515 }
516 } 516 }
517 517
518 for (i = 0; iforce->type->ff[i] >= 0; i++) 518 for (i = 0; iforce->type->ff[i] >= 0; i++)
519 set_bit(iforce->type->ff[i], iforce->dev.ffbit); 519 set_bit(iforce->type->ff[i], input_dev->ffbit);
520 520
521/* 521/*
522 * Register input device. 522 * Register input device.
523 */ 523 */
524 524
525 input_register_device(&iforce->dev); 525 input_register_device(iforce->dev);
526
527 printk(KERN_DEBUG "iforce->dev.open = %p\n", iforce->dev.open);
528 526
529 printk(KERN_INFO "input: %s [%d effects, %ld bytes memory]\n", 527 printk(KERN_DEBUG "iforce->dev->open = %p\n", iforce->dev->open);
530 iforce->dev.name, iforce->dev.ff_effects_max,
531 iforce->device_memory.end);
532 528
533 return 0; 529 return 0;
534} 530}
diff --git a/drivers/input/joystick/iforce/iforce-packets.c b/drivers/input/joystick/iforce/iforce-packets.c
index e5a31e55d3e2..4a2629243e19 100644
--- a/drivers/input/joystick/iforce/iforce-packets.c
+++ b/drivers/input/joystick/iforce/iforce-packets.c
@@ -139,7 +139,8 @@ printk(KERN_DEBUG "iforce-packets.c: control_playback %d %d\n", id, value);
139static int mark_core_as_ready(struct iforce *iforce, unsigned short addr) 139static int mark_core_as_ready(struct iforce *iforce, unsigned short addr)
140{ 140{
141 int i; 141 int i;
142 for (i=0; i<iforce->dev.ff_effects_max; ++i) { 142
143 for (i = 0; i < iforce->dev->ff_effects_max; ++i) {
143 if (test_bit(FF_CORE_IS_USED, iforce->core_effects[i].flags) && 144 if (test_bit(FF_CORE_IS_USED, iforce->core_effects[i].flags) &&
144 (iforce->core_effects[i].mod1_chunk.start == addr || 145 (iforce->core_effects[i].mod1_chunk.start == addr ||
145 iforce->core_effects[i].mod2_chunk.start == addr)) { 146 iforce->core_effects[i].mod2_chunk.start == addr)) {
@@ -153,7 +154,7 @@ static int mark_core_as_ready(struct iforce *iforce, unsigned short addr)
153 154
154void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data, struct pt_regs *regs) 155void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data, struct pt_regs *regs)
155{ 156{
156 struct input_dev *dev = &iforce->dev; 157 struct input_dev *dev = iforce->dev;
157 int i; 158 int i;
158 static int being_used = 0; 159 static int being_used = 0;
159 160
diff --git a/drivers/input/joystick/iforce/iforce-serio.c b/drivers/input/joystick/iforce/iforce-serio.c
index 11f51905cba7..64a78c515484 100644
--- a/drivers/input/joystick/iforce/iforce-serio.c
+++ b/drivers/input/joystick/iforce/iforce-serio.c
@@ -131,11 +131,10 @@ static int iforce_serio_connect(struct serio *serio, struct serio_driver *drv)
131 struct iforce *iforce; 131 struct iforce *iforce;
132 int err; 132 int err;
133 133
134 if (!(iforce = kmalloc(sizeof(struct iforce), GFP_KERNEL))) 134 iforce = kzalloc(sizeof(struct iforce), GFP_KERNEL);
135 if (!iforce)
135 return -ENOMEM; 136 return -ENOMEM;
136 137
137 memset(iforce, 0, sizeof(struct iforce));
138
139 iforce->bus = IFORCE_232; 138 iforce->bus = IFORCE_232;
140 iforce->serio = serio; 139 iforce->serio = serio;
141 140
@@ -148,7 +147,8 @@ static int iforce_serio_connect(struct serio *serio, struct serio_driver *drv)
148 return err; 147 return err;
149 } 148 }
150 149
151 if (iforce_init_device(iforce)) { 150 err = iforce_init_device(iforce);
151 if (err) {
152 serio_close(serio); 152 serio_close(serio);
153 serio_set_drvdata(serio, NULL); 153 serio_set_drvdata(serio, NULL);
154 kfree(iforce); 154 kfree(iforce);
@@ -162,7 +162,7 @@ static void iforce_serio_disconnect(struct serio *serio)
162{ 162{
163 struct iforce *iforce = serio_get_drvdata(serio); 163 struct iforce *iforce = serio_get_drvdata(serio);
164 164
165 input_unregister_device(&iforce->dev); 165 input_unregister_device(iforce->dev);
166 serio_close(serio); 166 serio_close(serio);
167 serio_set_drvdata(serio, NULL); 167 serio_set_drvdata(serio, NULL);
168 kfree(iforce); 168 kfree(iforce);
diff --git a/drivers/input/joystick/iforce/iforce-usb.c b/drivers/input/joystick/iforce/iforce-usb.c
index 58600f91eff5..64b4a3080985 100644
--- a/drivers/input/joystick/iforce/iforce-usb.c
+++ b/drivers/input/joystick/iforce/iforce-usb.c
@@ -135,28 +135,24 @@ static int iforce_usb_probe(struct usb_interface *intf,
135 struct usb_host_interface *interface; 135 struct usb_host_interface *interface;
136 struct usb_endpoint_descriptor *epirq, *epout; 136 struct usb_endpoint_descriptor *epirq, *epout;
137 struct iforce *iforce; 137 struct iforce *iforce;
138 int err = -ENOMEM;
138 139
139 interface = intf->cur_altsetting; 140 interface = intf->cur_altsetting;
140 141
141 epirq = &interface->endpoint[0].desc; 142 epirq = &interface->endpoint[0].desc;
142 epout = &interface->endpoint[1].desc; 143 epout = &interface->endpoint[1].desc;
143 144
144 if (!(iforce = kmalloc(sizeof(struct iforce) + 32, GFP_KERNEL))) 145 if (!(iforce = kzalloc(sizeof(struct iforce) + 32, GFP_KERNEL)))
145 goto fail; 146 goto fail;
146 147
147 memset(iforce, 0, sizeof(struct iforce)); 148 if (!(iforce->irq = usb_alloc_urb(0, GFP_KERNEL)))
148
149 if (!(iforce->irq = usb_alloc_urb(0, GFP_KERNEL))) {
150 goto fail; 149 goto fail;
151 }
152 150
153 if (!(iforce->out = usb_alloc_urb(0, GFP_KERNEL))) { 151 if (!(iforce->out = usb_alloc_urb(0, GFP_KERNEL)))
154 goto fail; 152 goto fail;
155 }
156 153
157 if (!(iforce->ctrl = usb_alloc_urb(0, GFP_KERNEL))) { 154 if (!(iforce->ctrl = usb_alloc_urb(0, GFP_KERNEL)))
158 goto fail; 155 goto fail;
159 }
160 156
161 iforce->bus = IFORCE_USB; 157 iforce->bus = IFORCE_USB;
162 iforce->usbdev = dev; 158 iforce->usbdev = dev;
@@ -174,7 +170,9 @@ static int iforce_usb_probe(struct usb_interface *intf,
174 usb_fill_control_urb(iforce->ctrl, dev, usb_rcvctrlpipe(dev, 0), 170 usb_fill_control_urb(iforce->ctrl, dev, usb_rcvctrlpipe(dev, 0),
175 (void*) &iforce->cr, iforce->edata, 16, iforce_usb_ctrl, iforce); 171 (void*) &iforce->cr, iforce->edata, 16, iforce_usb_ctrl, iforce);
176 172
177 if (iforce_init_device(iforce)) goto fail; 173 err = iforce_init_device(iforce);
174 if (err)
175 goto fail;
178 176
179 usb_set_intfdata(intf, iforce); 177 usb_set_intfdata(intf, iforce);
180 return 0; 178 return 0;
@@ -187,7 +185,7 @@ fail:
187 kfree(iforce); 185 kfree(iforce);
188 } 186 }
189 187
190 return -ENODEV; 188 return err;
191} 189}
192 190
193/* Called by iforce_delete() */ 191/* Called by iforce_delete() */
@@ -211,7 +209,7 @@ static void iforce_usb_disconnect(struct usb_interface *intf)
211 usb_set_intfdata(intf, NULL); 209 usb_set_intfdata(intf, NULL);
212 if (iforce) { 210 if (iforce) {
213 iforce->usbdev = NULL; 211 iforce->usbdev = NULL;
214 input_unregister_device(&iforce->dev); 212 input_unregister_device(iforce->dev);
215 213
216 if (!open) { 214 if (!open) {
217 iforce_delete_device(iforce); 215 iforce_delete_device(iforce);
diff --git a/drivers/input/joystick/iforce/iforce.h b/drivers/input/joystick/iforce/iforce.h
index bce247bc300b..146f406b8f8a 100644
--- a/drivers/input/joystick/iforce/iforce.h
+++ b/drivers/input/joystick/iforce/iforce.h
@@ -117,7 +117,7 @@ struct iforce_device {
117}; 117};
118 118
119struct iforce { 119struct iforce {
120 struct input_dev dev; /* Input device interface */ 120 struct input_dev *dev; /* Input device interface */
121 struct iforce_device *type; 121 struct iforce_device *type;
122 int bus; 122 int bus;
123 123
diff --git a/drivers/input/joystick/interact.c b/drivers/input/joystick/interact.c
index d7b3472bd686..8511ee7bb263 100644
--- a/drivers/input/joystick/interact.c
+++ b/drivers/input/joystick/interact.c
@@ -54,7 +54,7 @@ MODULE_LICENSE("GPL");
54 54
55struct interact { 55struct interact {
56 struct gameport *gameport; 56 struct gameport *gameport;
57 struct input_dev dev; 57 struct input_dev *dev;
58 int bads; 58 int bads;
59 int reads; 59 int reads;
60 unsigned char type; 60 unsigned char type;
@@ -130,7 +130,7 @@ static int interact_read_packet(struct gameport *gameport, int length, u32 *data
130static void interact_poll(struct gameport *gameport) 130static void interact_poll(struct gameport *gameport)
131{ 131{
132 struct interact *interact = gameport_get_drvdata(gameport); 132 struct interact *interact = gameport_get_drvdata(gameport);
133 struct input_dev *dev = &interact->dev; 133 struct input_dev *dev = interact->dev;
134 u32 data[3]; 134 u32 data[3];
135 int i; 135 int i;
136 136
@@ -208,14 +208,20 @@ static void interact_close(struct input_dev *dev)
208static int interact_connect(struct gameport *gameport, struct gameport_driver *drv) 208static int interact_connect(struct gameport *gameport, struct gameport_driver *drv)
209{ 209{
210 struct interact *interact; 210 struct interact *interact;
211 struct input_dev *input_dev;
211 __u32 data[3]; 212 __u32 data[3];
212 int i, t; 213 int i, t;
213 int err; 214 int err;
214 215
215 if (!(interact = kzalloc(sizeof(struct interact), GFP_KERNEL))) 216 interact = kzalloc(sizeof(struct interact), GFP_KERNEL);
216 return -ENOMEM; 217 input_dev = input_allocate_device();
218 if (!interact || !input_dev) {
219 err = -ENOMEM;
220 goto fail1;
221 }
217 222
218 interact->gameport = gameport; 223 interact->gameport = gameport;
224 interact->dev = input_dev;
219 225
220 gameport_set_drvdata(gameport, interact); 226 gameport_set_drvdata(gameport, interact);
221 227
@@ -249,41 +255,40 @@ static int interact_connect(struct gameport *gameport, struct gameport_driver *d
249 interact->type = i; 255 interact->type = i;
250 interact->length = interact_type[i].length; 256 interact->length = interact_type[i].length;
251 257
252 interact->dev.private = interact; 258 input_dev->name = interact_type[i].name;
253 interact->dev.open = interact_open; 259 input_dev->phys = interact->phys;
254 interact->dev.close = interact_close; 260 input_dev->id.bustype = BUS_GAMEPORT;
261 input_dev->id.vendor = GAMEPORT_ID_VENDOR_INTERACT;
262 input_dev->id.product = interact_type[i].id;
263 input_dev->id.version = 0x0100;
264 input_dev->private = interact;
255 265
256 interact->dev.name = interact_type[i].name; 266 input_dev->open = interact_open;
257 interact->dev.phys = interact->phys; 267 input_dev->close = interact_close;
258 interact->dev.id.bustype = BUS_GAMEPORT;
259 interact->dev.id.vendor = GAMEPORT_ID_VENDOR_INTERACT;
260 interact->dev.id.product = interact_type[i].id;
261 interact->dev.id.version = 0x0100;
262 268
263 interact->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 269 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
264 270
265 for (i = 0; (t = interact_type[interact->type].abs[i]) >= 0; i++) { 271 for (i = 0; (t = interact_type[interact->type].abs[i]) >= 0; i++) {
266 set_bit(t, interact->dev.absbit); 272 set_bit(t, input_dev->absbit);
267 if (i < interact_type[interact->type].b8) { 273 if (i < interact_type[interact->type].b8) {
268 interact->dev.absmin[t] = 0; 274 input_dev->absmin[t] = 0;
269 interact->dev.absmax[t] = 255; 275 input_dev->absmax[t] = 255;
270 } else { 276 } else {
271 interact->dev.absmin[t] = -1; 277 input_dev->absmin[t] = -1;
272 interact->dev.absmax[t] = 1; 278 input_dev->absmax[t] = 1;
273 } 279 }
274 } 280 }
275 281
276 for (i = 0; (t = interact_type[interact->type].btn[i]) >= 0; i++) 282 for (i = 0; (t = interact_type[interact->type].btn[i]) >= 0; i++)
277 set_bit(t, interact->dev.keybit); 283 set_bit(t, input_dev->keybit);
278 284
279 input_register_device(&interact->dev); 285 input_register_device(interact->dev);
280 printk(KERN_INFO "input: %s on %s\n",
281 interact_type[interact->type].name, gameport->phys);
282 286
283 return 0; 287 return 0;
284 288
285fail2: gameport_close(gameport); 289fail2: gameport_close(gameport);
286fail1: gameport_set_drvdata(gameport, NULL); 290fail1: gameport_set_drvdata(gameport, NULL);
291 input_free_device(input_dev);
287 kfree(interact); 292 kfree(interact);
288 return err; 293 return err;
289} 294}
@@ -292,7 +297,7 @@ static void interact_disconnect(struct gameport *gameport)
292{ 297{
293 struct interact *interact = gameport_get_drvdata(gameport); 298 struct interact *interact = gameport_get_drvdata(gameport);
294 299
295 input_unregister_device(&interact->dev); 300 input_unregister_device(interact->dev);
296 gameport_close(gameport); 301 gameport_close(gameport);
297 gameport_set_drvdata(gameport, NULL); 302 gameport_set_drvdata(gameport, NULL);
298 kfree(interact); 303 kfree(interact);
diff --git a/drivers/input/joystick/magellan.c b/drivers/input/joystick/magellan.c
index 1ba503627242..ca3cc2319d6a 100644
--- a/drivers/input/joystick/magellan.c
+++ b/drivers/input/joystick/magellan.c
@@ -49,14 +49,13 @@ MODULE_LICENSE("GPL");
49 49
50static int magellan_buttons[] = { BTN_0, BTN_1, BTN_2, BTN_3, BTN_4, BTN_5, BTN_6, BTN_7, BTN_8 }; 50static int magellan_buttons[] = { BTN_0, BTN_1, BTN_2, BTN_3, BTN_4, BTN_5, BTN_6, BTN_7, BTN_8 };
51static int magellan_axes[] = { ABS_X, ABS_Y, ABS_Z, ABS_RX, ABS_RY, ABS_RZ }; 51static int magellan_axes[] = { ABS_X, ABS_Y, ABS_Z, ABS_RX, ABS_RY, ABS_RZ };
52static char *magellan_name = "LogiCad3D Magellan / SpaceMouse";
53 52
54/* 53/*
55 * Per-Magellan data. 54 * Per-Magellan data.
56 */ 55 */
57 56
58struct magellan { 57struct magellan {
59 struct input_dev dev; 58 struct input_dev *dev;
60 int idx; 59 int idx;
61 unsigned char data[MAGELLAN_MAX_LENGTH]; 60 unsigned char data[MAGELLAN_MAX_LENGTH];
62 char phys[32]; 61 char phys[32];
@@ -85,7 +84,7 @@ static int magellan_crunch_nibbles(unsigned char *data, int count)
85 84
86static void magellan_process_packet(struct magellan* magellan, struct pt_regs *regs) 85static void magellan_process_packet(struct magellan* magellan, struct pt_regs *regs)
87{ 86{
88 struct input_dev *dev = &magellan->dev; 87 struct input_dev *dev = magellan->dev;
89 unsigned char *data = magellan->data; 88 unsigned char *data = magellan->data;
90 int i, t; 89 int i, t;
91 90
@@ -138,9 +137,9 @@ static void magellan_disconnect(struct serio *serio)
138{ 137{
139 struct magellan* magellan = serio_get_drvdata(serio); 138 struct magellan* magellan = serio_get_drvdata(serio);
140 139
141 input_unregister_device(&magellan->dev);
142 serio_close(serio); 140 serio_close(serio);
143 serio_set_drvdata(serio, NULL); 141 serio_set_drvdata(serio, NULL);
142 input_unregister_device(magellan->dev);
144 kfree(magellan); 143 kfree(magellan);
145} 144}
146 145
@@ -153,52 +152,48 @@ static void magellan_disconnect(struct serio *serio)
153static int magellan_connect(struct serio *serio, struct serio_driver *drv) 152static int magellan_connect(struct serio *serio, struct serio_driver *drv)
154{ 153{
155 struct magellan *magellan; 154 struct magellan *magellan;
156 int i, t; 155 struct input_dev *input_dev;
157 int err; 156 int err = -ENOMEM;
158 157 int i;
159 if (!(magellan = kmalloc(sizeof(struct magellan), GFP_KERNEL)))
160 return -ENOMEM;
161 158
162 memset(magellan, 0, sizeof(struct magellan)); 159 magellan = kzalloc(sizeof(struct magellan), GFP_KERNEL);
160 input_dev = input_allocate_device();
161 if (!magellan || !input_dev)
162 goto fail;
163 163
164 magellan->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 164 magellan->dev = input_dev;
165 sprintf(magellan->phys, "%s/input0", serio->phys);
165 166
166 for (i = 0; i < 9; i++) 167 input_dev->name = "LogiCad3D Magellan / SpaceMouse";
167 set_bit(magellan_buttons[i], magellan->dev.keybit); 168 input_dev->phys = magellan->phys;
169 input_dev->id.bustype = BUS_RS232;
170 input_dev->id.vendor = SERIO_MAGELLAN;
171 input_dev->id.product = 0x0001;
172 input_dev->id.version = 0x0100;
173 input_dev->cdev.dev = &serio->dev;
174 input_dev->private = magellan;
168 175
169 for (i = 0; i < 6; i++) { 176 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
170 t = magellan_axes[i];
171 set_bit(t, magellan->dev.absbit);
172 magellan->dev.absmin[t] = -360;
173 magellan->dev.absmax[t] = 360;
174 }
175 177
176 sprintf(magellan->phys, "%s/input0", serio->phys); 178 for (i = 0; i < 9; i++)
179 set_bit(magellan_buttons[i], input_dev->keybit);
177 180
178 init_input_dev(&magellan->dev); 181 for (i = 0; i < 6; i++)
179 magellan->dev.private = magellan; 182 input_set_abs_params(input_dev, magellan_axes[i], -360, 360, 0, 0);
180 magellan->dev.name = magellan_name;
181 magellan->dev.phys = magellan->phys;
182 magellan->dev.id.bustype = BUS_RS232;
183 magellan->dev.id.vendor = SERIO_MAGELLAN;
184 magellan->dev.id.product = 0x0001;
185 magellan->dev.id.version = 0x0100;
186 magellan->dev.dev = &serio->dev;
187 183
188 serio_set_drvdata(serio, magellan); 184 serio_set_drvdata(serio, magellan);
189 185
190 err = serio_open(serio, drv); 186 err = serio_open(serio, drv);
191 if (err) { 187 if (err)
192 serio_set_drvdata(serio, NULL); 188 goto fail;
193 kfree(magellan);
194 return err;
195 }
196
197 input_register_device(&magellan->dev);
198
199 printk(KERN_INFO "input: %s on %s\n", magellan_name, serio->phys);
200 189
190 input_register_device(magellan->dev);
201 return 0; 191 return 0;
192
193 fail: serio_set_drvdata(serio, NULL);
194 input_free_device(input_dev);
195 kfree(magellan);
196 return err;
202} 197}
203 198
204/* 199/*
diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
index 9e0353721a35..eaaad45cc750 100644
--- a/drivers/input/joystick/sidewinder.c
+++ b/drivers/input/joystick/sidewinder.c
@@ -113,7 +113,7 @@ static struct {
113 113
114struct sw { 114struct sw {
115 struct gameport *gameport; 115 struct gameport *gameport;
116 struct input_dev dev[4]; 116 struct input_dev *dev[4];
117 char name[64]; 117 char name[64];
118 char phys[4][32]; 118 char phys[4][32];
119 int length; 119 int length;
@@ -301,7 +301,7 @@ static int sw_check(__u64 t)
301static int sw_parse(unsigned char *buf, struct sw *sw) 301static int sw_parse(unsigned char *buf, struct sw *sw)
302{ 302{
303 int hat, i, j; 303 int hat, i, j;
304 struct input_dev *dev = sw->dev; 304 struct input_dev *dev;
305 305
306 switch (sw->type) { 306 switch (sw->type) {
307 307
@@ -310,6 +310,8 @@ static int sw_parse(unsigned char *buf, struct sw *sw)
310 if (sw_check(GB(0,64)) || (hat = (GB(6,1) << 3) | GB(60,3)) > 8) 310 if (sw_check(GB(0,64)) || (hat = (GB(6,1) << 3) | GB(60,3)) > 8)
311 return -1; 311 return -1;
312 312
313 dev = sw->dev[0];
314
313 input_report_abs(dev, ABS_X, (GB( 3,3) << 7) | GB(16,7)); 315 input_report_abs(dev, ABS_X, (GB( 3,3) << 7) | GB(16,7));
314 input_report_abs(dev, ABS_Y, (GB( 0,3) << 7) | GB(24,7)); 316 input_report_abs(dev, ABS_Y, (GB( 0,3) << 7) | GB(24,7));
315 input_report_abs(dev, ABS_RZ, (GB(35,2) << 7) | GB(40,7)); 317 input_report_abs(dev, ABS_RZ, (GB(35,2) << 7) | GB(40,7));
@@ -335,13 +337,13 @@ static int sw_parse(unsigned char *buf, struct sw *sw)
335 if (sw_parity(GB(i*15,15))) 337 if (sw_parity(GB(i*15,15)))
336 return -1; 338 return -1;
337 339
338 input_report_abs(dev + i, ABS_X, GB(i*15+3,1) - GB(i*15+2,1)); 340 input_report_abs(sw->dev[i], ABS_X, GB(i*15+3,1) - GB(i*15+2,1));
339 input_report_abs(dev + i, ABS_Y, GB(i*15+0,1) - GB(i*15+1,1)); 341 input_report_abs(sw->dev[i], ABS_Y, GB(i*15+0,1) - GB(i*15+1,1));
340 342
341 for (j = 0; j < 10; j++) 343 for (j = 0; j < 10; j++)
342 input_report_key(dev + i, sw_btn[SW_ID_GP][j], !GB(i*15+j+4,1)); 344 input_report_key(sw->dev[i], sw_btn[SW_ID_GP][j], !GB(i*15+j+4,1));
343 345
344 input_sync(dev + i); 346 input_sync(sw->dev[i]);
345 } 347 }
346 348
347 return 0; 349 return 0;
@@ -352,6 +354,7 @@ static int sw_parse(unsigned char *buf, struct sw *sw)
352 if (!sw_parity(GB(0,48)) || (hat = GB(42,4)) > 8) 354 if (!sw_parity(GB(0,48)) || (hat = GB(42,4)) > 8)
353 return -1; 355 return -1;
354 356
357 dev = sw->dev[0];
355 input_report_abs(dev, ABS_X, GB( 9,10)); 358 input_report_abs(dev, ABS_X, GB( 9,10));
356 input_report_abs(dev, ABS_Y, GB(19,10)); 359 input_report_abs(dev, ABS_Y, GB(19,10));
357 input_report_abs(dev, ABS_RZ, GB(36, 6)); 360 input_report_abs(dev, ABS_RZ, GB(36, 6));
@@ -372,6 +375,7 @@ static int sw_parse(unsigned char *buf, struct sw *sw)
372 if (!sw_parity(GB(0,43)) || (hat = GB(28,4)) > 8) 375 if (!sw_parity(GB(0,43)) || (hat = GB(28,4)) > 8)
373 return -1; 376 return -1;
374 377
378 dev = sw->dev[0];
375 input_report_abs(dev, ABS_X, GB( 0,10)); 379 input_report_abs(dev, ABS_X, GB( 0,10));
376 input_report_abs(dev, ABS_Y, GB(16,10)); 380 input_report_abs(dev, ABS_Y, GB(16,10));
377 input_report_abs(dev, ABS_THROTTLE, GB(32, 6)); 381 input_report_abs(dev, ABS_THROTTLE, GB(32, 6));
@@ -396,6 +400,7 @@ static int sw_parse(unsigned char *buf, struct sw *sw)
396 if (!sw_parity(GB(0,33))) 400 if (!sw_parity(GB(0,33)))
397 return -1; 401 return -1;
398 402
403 dev = sw->dev[0];
399 input_report_abs(dev, ABS_RX, GB( 0,10)); 404 input_report_abs(dev, ABS_RX, GB( 0,10));
400 input_report_abs(dev, ABS_RUDDER, GB(10, 6)); 405 input_report_abs(dev, ABS_RUDDER, GB(10, 6));
401 input_report_abs(dev, ABS_THROTTLE, GB(16, 6)); 406 input_report_abs(dev, ABS_THROTTLE, GB(16, 6));
@@ -581,6 +586,7 @@ static int sw_guess_mode(unsigned char *buf, int len)
581static int sw_connect(struct gameport *gameport, struct gameport_driver *drv) 586static int sw_connect(struct gameport *gameport, struct gameport_driver *drv)
582{ 587{
583 struct sw *sw; 588 struct sw *sw;
589 struct input_dev *input_dev;
584 int i, j, k, l; 590 int i, j, k, l;
585 int err; 591 int err;
586 unsigned char *buf = NULL; /* [SW_LENGTH] */ 592 unsigned char *buf = NULL; /* [SW_LENGTH] */
@@ -729,42 +735,50 @@ static int sw_connect(struct gameport *gameport, struct gameport_driver *drv)
729 sprintf(sw->name, "Microsoft SideWinder %s", sw_name[sw->type]); 735 sprintf(sw->name, "Microsoft SideWinder %s", sw_name[sw->type]);
730 sprintf(sw->phys[i], "%s/input%d", gameport->phys, i); 736 sprintf(sw->phys[i], "%s/input%d", gameport->phys, i);
731 737
732 sw->dev[i].private = sw; 738 input_dev = input_allocate_device();
739 if (!input_dev) {
740 err = -ENOMEM;
741 goto fail3;
742 }
733 743
734 sw->dev[i].open = sw_open; 744 input_dev->name = sw->name;
735 sw->dev[i].close = sw_close; 745 input_dev->phys = sw->phys[i];
746 input_dev->id.bustype = BUS_GAMEPORT;
747 input_dev->id.vendor = GAMEPORT_ID_VENDOR_MICROSOFT;
748 input_dev->id.product = sw->type;
749 input_dev->id.version = 0x0100;
750 input_dev->cdev.dev = &gameport->dev;
751 input_dev->private = sw;
736 752
737 sw->dev[i].name = sw->name; 753 input_dev->open = sw_open;
738 sw->dev[i].phys = sw->phys[i]; 754 input_dev->close = sw_close;
739 sw->dev[i].id.bustype = BUS_GAMEPORT;
740 sw->dev[i].id.vendor = GAMEPORT_ID_VENDOR_MICROSOFT;
741 sw->dev[i].id.product = sw->type;
742 sw->dev[i].id.version = 0x0100;
743 755
744 sw->dev[i].evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 756 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
745 757
746 for (j = 0; (bits = sw_bit[sw->type][j]); j++) { 758 for (j = 0; (bits = sw_bit[sw->type][j]); j++) {
747 code = sw_abs[sw->type][j]; 759 code = sw_abs[sw->type][j];
748 set_bit(code, sw->dev[i].absbit); 760 set_bit(code, input_dev->absbit);
749 sw->dev[i].absmax[code] = (1 << bits) - 1; 761 input_dev->absmax[code] = (1 << bits) - 1;
750 sw->dev[i].absmin[code] = (bits == 1) ? -1 : 0; 762 input_dev->absmin[code] = (bits == 1) ? -1 : 0;
751 sw->dev[i].absfuzz[code] = ((bits >> 1) >= 2) ? (1 << ((bits >> 1) - 2)) : 0; 763 input_dev->absfuzz[code] = ((bits >> 1) >= 2) ? (1 << ((bits >> 1) - 2)) : 0;
752 if (code != ABS_THROTTLE) 764 if (code != ABS_THROTTLE)
753 sw->dev[i].absflat[code] = (bits >= 5) ? (1 << (bits - 5)) : 0; 765 input_dev->absflat[code] = (bits >= 5) ? (1 << (bits - 5)) : 0;
754 } 766 }
755 767
756 for (j = 0; (code = sw_btn[sw->type][j]); j++) 768 for (j = 0; (code = sw_btn[sw->type][j]); j++)
757 set_bit(code, sw->dev[i].keybit); 769 set_bit(code, input_dev->keybit);
770
771 dbg("%s%s [%d-bit id %d data %d]\n", sw->name, comment, m, l, k);
758 772
759 input_register_device(sw->dev + i); 773 input_register_device(sw->dev[i]);
760 printk(KERN_INFO "input: %s%s on %s [%d-bit id %d data %d]\n",
761 sw->name, comment, gameport->phys, m, l, k);
762 } 774 }
763 775
764 return 0; 776 return 0;
765 777
766fail2: gameport_close(gameport); 778 fail3: while (--i >= 0)
767fail1: gameport_set_drvdata(gameport, NULL); 779 input_unregister_device(sw->dev[i]);
780 fail2: gameport_close(gameport);
781 fail1: gameport_set_drvdata(gameport, NULL);
768 kfree(sw); 782 kfree(sw);
769 kfree(buf); 783 kfree(buf);
770 kfree(idbuf); 784 kfree(idbuf);
@@ -777,7 +791,7 @@ static void sw_disconnect(struct gameport *gameport)
777 int i; 791 int i;
778 792
779 for (i = 0; i < sw->number; i++) 793 for (i = 0; i < sw->number; i++)
780 input_unregister_device(sw->dev + i); 794 input_unregister_device(sw->dev[i]);
781 gameport_close(gameport); 795 gameport_close(gameport);
782 gameport_set_drvdata(gameport, NULL); 796 gameport_set_drvdata(gameport, NULL);
783 kfree(sw); 797 kfree(sw);
diff --git a/drivers/input/joystick/spaceball.c b/drivers/input/joystick/spaceball.c
index a436f2220856..d6f8db8ec3fd 100644
--- a/drivers/input/joystick/spaceball.c
+++ b/drivers/input/joystick/spaceball.c
@@ -70,8 +70,7 @@ static char *spaceball_names[] = {
70 */ 70 */
71 71
72struct spaceball { 72struct spaceball {
73 struct input_dev dev; 73 struct input_dev *dev;
74 struct serio *serio;
75 int idx; 74 int idx;
76 int escape; 75 int escape;
77 unsigned char data[SPACEBALL_MAX_LENGTH]; 76 unsigned char data[SPACEBALL_MAX_LENGTH];
@@ -85,7 +84,7 @@ struct spaceball {
85 84
86static void spaceball_process_packet(struct spaceball* spaceball, struct pt_regs *regs) 85static void spaceball_process_packet(struct spaceball* spaceball, struct pt_regs *regs)
87{ 86{
88 struct input_dev *dev = &spaceball->dev; 87 struct input_dev *dev = spaceball->dev;
89 unsigned char *data = spaceball->data; 88 unsigned char *data = spaceball->data;
90 int i; 89 int i;
91 90
@@ -193,9 +192,9 @@ static void spaceball_disconnect(struct serio *serio)
193{ 192{
194 struct spaceball* spaceball = serio_get_drvdata(serio); 193 struct spaceball* spaceball = serio_get_drvdata(serio);
195 194
196 input_unregister_device(&spaceball->dev);
197 serio_close(serio); 195 serio_close(serio);
198 serio_set_drvdata(serio, NULL); 196 serio_set_drvdata(serio, NULL);
197 input_unregister_device(spaceball->dev);
199 kfree(spaceball); 198 kfree(spaceball);
200} 199}
201 200
@@ -208,69 +207,62 @@ static void spaceball_disconnect(struct serio *serio)
208static int spaceball_connect(struct serio *serio, struct serio_driver *drv) 207static int spaceball_connect(struct serio *serio, struct serio_driver *drv)
209{ 208{
210 struct spaceball *spaceball; 209 struct spaceball *spaceball;
211 int i, t, id; 210 struct input_dev *input_dev;
212 int err; 211 int err = -ENOMEM;
212 int i, id;
213 213
214 if ((id = serio->id.id) > SPACEBALL_MAX_ID) 214 if ((id = serio->id.id) > SPACEBALL_MAX_ID)
215 return -ENODEV; 215 return -ENODEV;
216 216
217 if (!(spaceball = kmalloc(sizeof(struct spaceball), GFP_KERNEL))) 217 spaceball = kmalloc(sizeof(struct spaceball), GFP_KERNEL);
218 return - ENOMEM; 218 input_dev = input_allocate_device();
219 if (!spaceball || !input_dev)
220 goto fail;
219 221
220 memset(spaceball, 0, sizeof(struct spaceball)); 222 spaceball->dev = input_dev;
223 sprintf(spaceball->phys, "%s/input0", serio->phys);
224
225 input_dev->name = spaceball_names[id];
226 input_dev->phys = spaceball->phys;
227 input_dev->id.bustype = BUS_RS232;
228 input_dev->id.vendor = SERIO_SPACEBALL;
229 input_dev->id.product = id;
230 input_dev->id.version = 0x0100;
231 input_dev->cdev.dev = &serio->dev;
232 input_dev->private = spaceball;
221 233
222 spaceball->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 234 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
223 235
224 switch (id) { 236 switch (id) {
225 case SPACEBALL_4000FLX: 237 case SPACEBALL_4000FLX:
226 case SPACEBALL_4000FLX_L: 238 case SPACEBALL_4000FLX_L:
227 spaceball->dev.keybit[LONG(BTN_0)] |= BIT(BTN_9); 239 input_dev->keybit[LONG(BTN_0)] |= BIT(BTN_9);
228 spaceball->dev.keybit[LONG(BTN_A)] |= BIT(BTN_A) | BIT(BTN_B) | BIT(BTN_C) | BIT(BTN_MODE); 240 input_dev->keybit[LONG(BTN_A)] |= BIT(BTN_A) | BIT(BTN_B) | BIT(BTN_C) | BIT(BTN_MODE);
229 default: 241 default:
230 spaceball->dev.keybit[LONG(BTN_0)] |= BIT(BTN_2) | BIT(BTN_3) | BIT(BTN_4) 242 input_dev->keybit[LONG(BTN_0)] |= BIT(BTN_2) | BIT(BTN_3) | BIT(BTN_4)
231 | BIT(BTN_5) | BIT(BTN_6) | BIT(BTN_7) | BIT(BTN_8); 243 | BIT(BTN_5) | BIT(BTN_6) | BIT(BTN_7) | BIT(BTN_8);
232 case SPACEBALL_3003C: 244 case SPACEBALL_3003C:
233 spaceball->dev.keybit[LONG(BTN_0)] |= BIT(BTN_1) | BIT(BTN_8); 245 input_dev->keybit[LONG(BTN_0)] |= BIT(BTN_1) | BIT(BTN_8);
234 } 246 }
235 247
236 for (i = 0; i < 6; i++) { 248 for (i = 0; i < 3; i++) {
237 t = spaceball_axes[i]; 249 input_set_abs_params(input_dev, ABS_X + i, -8000, 8000, 8, 40);
238 set_bit(t, spaceball->dev.absbit); 250 input_set_abs_params(input_dev, ABS_RX + i, -1600, 1600, 2, 8);
239 spaceball->dev.absmin[t] = i < 3 ? -8000 : -1600;
240 spaceball->dev.absmax[t] = i < 3 ? 8000 : 1600;
241 spaceball->dev.absflat[t] = i < 3 ? 40 : 8;
242 spaceball->dev.absfuzz[t] = i < 3 ? 8 : 2;
243 } 251 }
244 252
245 spaceball->serio = serio;
246 spaceball->dev.private = spaceball;
247
248 sprintf(spaceball->phys, "%s/input0", serio->phys);
249
250 init_input_dev(&spaceball->dev);
251 spaceball->dev.name = spaceball_names[id];
252 spaceball->dev.phys = spaceball->phys;
253 spaceball->dev.id.bustype = BUS_RS232;
254 spaceball->dev.id.vendor = SERIO_SPACEBALL;
255 spaceball->dev.id.product = id;
256 spaceball->dev.id.version = 0x0100;
257 spaceball->dev.dev = &serio->dev;
258
259 serio_set_drvdata(serio, spaceball); 253 serio_set_drvdata(serio, spaceball);
260 254
261 err = serio_open(serio, drv); 255 err = serio_open(serio, drv);
262 if (err) { 256 if (err)
263 serio_set_drvdata(serio, NULL); 257 goto fail;
264 kfree(spaceball);
265 return err;
266 }
267
268 input_register_device(&spaceball->dev);
269
270 printk(KERN_INFO "input: %s on serio%s\n",
271 spaceball_names[id], serio->phys);
272 258
259 input_register_device(spaceball->dev);
273 return 0; 260 return 0;
261
262 fail: serio_set_drvdata(serio, NULL);
263 input_free_device(input_dev);
264 kfree(spaceball);
265 return err;
274} 266}
275 267
276/* 268/*
diff --git a/drivers/input/joystick/spaceorb.c b/drivers/input/joystick/spaceorb.c
index 01fd2e4791ae..7c123a01c58e 100644
--- a/drivers/input/joystick/spaceorb.c
+++ b/drivers/input/joystick/spaceorb.c
@@ -52,15 +52,13 @@ MODULE_LICENSE("GPL");
52 52
53static int spaceorb_buttons[] = { BTN_TL, BTN_TR, BTN_Y, BTN_X, BTN_B, BTN_A }; 53static int spaceorb_buttons[] = { BTN_TL, BTN_TR, BTN_Y, BTN_X, BTN_B, BTN_A };
54static int spaceorb_axes[] = { ABS_X, ABS_Y, ABS_Z, ABS_RX, ABS_RY, ABS_RZ }; 54static int spaceorb_axes[] = { ABS_X, ABS_Y, ABS_Z, ABS_RX, ABS_RY, ABS_RZ };
55static char *spaceorb_name = "SpaceTec SpaceOrb 360 / Avenger";
56 55
57/* 56/*
58 * Per-Orb data. 57 * Per-Orb data.
59 */ 58 */
60 59
61struct spaceorb { 60struct spaceorb {
62 struct input_dev dev; 61 struct input_dev *dev;
63 struct serio *serio;
64 int idx; 62 int idx;
65 unsigned char data[SPACEORB_MAX_LENGTH]; 63 unsigned char data[SPACEORB_MAX_LENGTH];
66 char phys[32]; 64 char phys[32];
@@ -78,7 +76,7 @@ static unsigned char *spaceorb_errors[] = { "EEPROM storing 0 failed", "Receive
78 76
79static void spaceorb_process_packet(struct spaceorb *spaceorb, struct pt_regs *regs) 77static void spaceorb_process_packet(struct spaceorb *spaceorb, struct pt_regs *regs)
80{ 78{
81 struct input_dev *dev = &spaceorb->dev; 79 struct input_dev *dev = spaceorb->dev;
82 unsigned char *data = spaceorb->data; 80 unsigned char *data = spaceorb->data;
83 unsigned char c = 0; 81 unsigned char c = 0;
84 int axes[6]; 82 int axes[6];
@@ -95,8 +93,8 @@ static void spaceorb_process_packet(struct spaceorb *spaceorb, struct pt_regs *r
95 case 'R': /* Reset packet */ 93 case 'R': /* Reset packet */
96 spaceorb->data[spaceorb->idx - 1] = 0; 94 spaceorb->data[spaceorb->idx - 1] = 0;
97 for (i = 1; i < spaceorb->idx && spaceorb->data[i] == ' '; i++); 95 for (i = 1; i < spaceorb->idx && spaceorb->data[i] == ' '; i++);
98 printk(KERN_INFO "input: %s [%s] on %s\n", 96 printk(KERN_INFO "input: %s [%s] is %s\n",
99 spaceorb_name, spaceorb->data + i, spaceorb->serio->phys); 97 dev->name, spaceorb->data + i, spaceorb->phys);
100 break; 98 break;
101 99
102 case 'D': /* Ball + button data */ 100 case 'D': /* Ball + button data */
@@ -123,7 +121,7 @@ static void spaceorb_process_packet(struct spaceorb *spaceorb, struct pt_regs *r
123 121
124 case 'E': /* Error packet */ 122 case 'E': /* Error packet */
125 if (spaceorb->idx != 4) return; 123 if (spaceorb->idx != 4) return;
126 printk(KERN_ERR "joy-spaceorb: Device error. [ "); 124 printk(KERN_ERR "spaceorb: Device error. [ ");
127 for (i = 0; i < 7; i++) if (data[1] & (1 << i)) printk("%s ", spaceorb_errors[i]); 125 for (i = 0; i < 7; i++) if (data[1] & (1 << i)) printk("%s ", spaceorb_errors[i]);
128 printk("]\n"); 126 printk("]\n");
129 break; 127 break;
@@ -154,9 +152,9 @@ static void spaceorb_disconnect(struct serio *serio)
154{ 152{
155 struct spaceorb* spaceorb = serio_get_drvdata(serio); 153 struct spaceorb* spaceorb = serio_get_drvdata(serio);
156 154
157 input_unregister_device(&spaceorb->dev);
158 serio_close(serio); 155 serio_close(serio);
159 serio_set_drvdata(serio, NULL); 156 serio_set_drvdata(serio, NULL);
157 input_unregister_device(spaceorb->dev);
160 kfree(spaceorb); 158 kfree(spaceorb);
161} 159}
162 160
@@ -169,52 +167,48 @@ static void spaceorb_disconnect(struct serio *serio)
169static int spaceorb_connect(struct serio *serio, struct serio_driver *drv) 167static int spaceorb_connect(struct serio *serio, struct serio_driver *drv)
170{ 168{
171 struct spaceorb *spaceorb; 169 struct spaceorb *spaceorb;
172 int i, t; 170 struct input_dev *input_dev;
173 int err; 171 int err = -ENOMEM;
174 172 int i;
175 if (!(spaceorb = kmalloc(sizeof(struct spaceorb), GFP_KERNEL)))
176 return -ENOMEM;
177
178 memset(spaceorb, 0, sizeof(struct spaceorb));
179 173
180 spaceorb->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 174 spaceorb = kzalloc(sizeof(struct spaceorb), GFP_KERNEL);
175 input_dev = input_allocate_device();
176 if (!spaceorb || !input_dev)
177 goto fail;
181 178
182 for (i = 0; i < 6; i++) 179 spaceorb->dev = input_dev;
183 set_bit(spaceorb_buttons[i], spaceorb->dev.keybit); 180 sprintf(spaceorb->phys, "%s/input0", serio->phys);
184 181
185 for (i = 0; i < 6; i++) { 182 input_dev->name = "SpaceTec SpaceOrb 360 / Avenger";
186 t = spaceorb_axes[i]; 183 input_dev->phys = spaceorb->phys;
187 set_bit(t, spaceorb->dev.absbit); 184 input_dev->id.bustype = BUS_RS232;
188 spaceorb->dev.absmin[t] = -508; 185 input_dev->id.vendor = SERIO_SPACEORB;
189 spaceorb->dev.absmax[t] = 508; 186 input_dev->id.product = 0x0001;
190 } 187 input_dev->id.version = 0x0100;
188 input_dev->cdev.dev = &serio->dev;
189 input_dev->private = spaceorb;
191 190
192 spaceorb->serio = serio; 191 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
193 spaceorb->dev.private = spaceorb;
194 192
195 sprintf(spaceorb->phys, "%s/input0", serio->phys); 193 for (i = 0; i < 6; i++)
194 set_bit(spaceorb_buttons[i], input_dev->keybit);
196 195
197 init_input_dev(&spaceorb->dev); 196 for (i = 0; i < 6; i++)
198 spaceorb->dev.name = spaceorb_name; 197 input_set_abs_params(input_dev, spaceorb_axes[i], -508, 508, 0, 0);
199 spaceorb->dev.phys = spaceorb->phys;
200 spaceorb->dev.id.bustype = BUS_RS232;
201 spaceorb->dev.id.vendor = SERIO_SPACEORB;
202 spaceorb->dev.id.product = 0x0001;
203 spaceorb->dev.id.version = 0x0100;
204 spaceorb->dev.dev = &serio->dev;
205 198
206 serio_set_drvdata(serio, spaceorb); 199 serio_set_drvdata(serio, spaceorb);
207 200
208 err = serio_open(serio, drv); 201 err = serio_open(serio, drv);
209 if (err) { 202 if (err)
210 serio_set_drvdata(serio, NULL); 203 goto fail;
211 kfree(spaceorb);
212 return err;
213 }
214
215 input_register_device(&spaceorb->dev);
216 204
205 input_register_device(spaceorb->dev);
217 return 0; 206 return 0;
207
208 fail: serio_set_drvdata(serio, NULL);
209 input_free_device(input_dev);
210 kfree(spaceorb);
211 return err;
218} 212}
219 213
220/* 214/*
diff --git a/drivers/input/joystick/stinger.c b/drivers/input/joystick/stinger.c
index 6f6e6753d590..0a9ed1d30636 100644
--- a/drivers/input/joystick/stinger.c
+++ b/drivers/input/joystick/stinger.c
@@ -48,14 +48,12 @@ MODULE_LICENSE("GPL");
48 48
49#define STINGER_MAX_LENGTH 8 49#define STINGER_MAX_LENGTH 8
50 50
51static char *stinger_name = "Gravis Stinger";
52
53/* 51/*
54 * Per-Stinger data. 52 * Per-Stinger data.
55 */ 53 */
56 54
57struct stinger { 55struct stinger {
58 struct input_dev dev; 56 struct input_dev *dev;
59 int idx; 57 int idx;
60 unsigned char data[STINGER_MAX_LENGTH]; 58 unsigned char data[STINGER_MAX_LENGTH];
61 char phys[32]; 59 char phys[32];
@@ -68,7 +66,7 @@ struct stinger {
68 66
69static void stinger_process_packet(struct stinger *stinger, struct pt_regs *regs) 67static void stinger_process_packet(struct stinger *stinger, struct pt_regs *regs)
70{ 68{
71 struct input_dev *dev = &stinger->dev; 69 struct input_dev *dev = stinger->dev;
72 unsigned char *data = stinger->data; 70 unsigned char *data = stinger->data;
73 71
74 if (!stinger->idx) return; 72 if (!stinger->idx) return;
@@ -126,9 +124,9 @@ static void stinger_disconnect(struct serio *serio)
126{ 124{
127 struct stinger *stinger = serio_get_drvdata(serio); 125 struct stinger *stinger = serio_get_drvdata(serio);
128 126
129 input_unregister_device(&stinger->dev);
130 serio_close(serio); 127 serio_close(serio);
131 serio_set_drvdata(serio, NULL); 128 serio_set_drvdata(serio, NULL);
129 input_unregister_device(stinger->dev);
132 kfree(stinger); 130 kfree(stinger);
133} 131}
134 132
@@ -141,53 +139,46 @@ static void stinger_disconnect(struct serio *serio)
141static int stinger_connect(struct serio *serio, struct serio_driver *drv) 139static int stinger_connect(struct serio *serio, struct serio_driver *drv)
142{ 140{
143 struct stinger *stinger; 141 struct stinger *stinger;
144 int i; 142 struct input_dev *input_dev;
145 int err; 143 int err = -ENOMEM;
146
147 if (!(stinger = kmalloc(sizeof(struct stinger), GFP_KERNEL)))
148 return -ENOMEM;
149
150 memset(stinger, 0, sizeof(struct stinger));
151 144
152 stinger->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 145 stinger = kmalloc(sizeof(struct stinger), GFP_KERNEL);
153 stinger->dev.keybit[LONG(BTN_A)] = BIT(BTN_A) | BIT(BTN_B) | BIT(BTN_C) | BIT(BTN_X) | \ 146 input_dev = input_allocate_device();
154 BIT(BTN_Y) | BIT(BTN_Z) | BIT(BTN_TL) | BIT(BTN_TR) | \ 147 if (!stinger || !input_dev)
155 BIT(BTN_START) | BIT(BTN_SELECT); 148 goto fail;
156 stinger->dev.absbit[0] = BIT(ABS_X) | BIT(ABS_Y);
157 149
150 stinger->dev = input_dev;
158 sprintf(stinger->phys, "%s/serio0", serio->phys); 151 sprintf(stinger->phys, "%s/serio0", serio->phys);
159 152
160 init_input_dev(&stinger->dev); 153 input_dev->name = "Gravis Stinger";
161 stinger->dev.name = stinger_name; 154 input_dev->phys = stinger->phys;
162 stinger->dev.phys = stinger->phys; 155 input_dev->id.bustype = BUS_RS232;
163 stinger->dev.id.bustype = BUS_RS232; 156 input_dev->id.vendor = SERIO_STINGER;
164 stinger->dev.id.vendor = SERIO_STINGER; 157 input_dev->id.product = 0x0001;
165 stinger->dev.id.product = 0x0001; 158 input_dev->id.version = 0x0100;
166 stinger->dev.id.version = 0x0100; 159 input_dev->cdev.dev = &serio->dev;
167 stinger->dev.dev = &serio->dev; 160 input_dev->private = stinger;
168 161
169 for (i = 0; i < 2; i++) { 162 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
170 stinger->dev.absmax[ABS_X+i] = 64; 163 input_dev->keybit[LONG(BTN_A)] = BIT(BTN_A) | BIT(BTN_B) | BIT(BTN_C) | BIT(BTN_X) |
171 stinger->dev.absmin[ABS_X+i] = -64; 164 BIT(BTN_Y) | BIT(BTN_Z) | BIT(BTN_TL) | BIT(BTN_TR) |
172 stinger->dev.absflat[ABS_X+i] = 4; 165 BIT(BTN_START) | BIT(BTN_SELECT);
173 } 166 input_set_abs_params(input_dev, ABS_X, -64, 64, 0, 4);
174 167 input_set_abs_params(input_dev, ABS_Y, -64, 64, 0, 4);
175 stinger->dev.private = stinger;
176 168
177 serio_set_drvdata(serio, stinger); 169 serio_set_drvdata(serio, stinger);
178 170
179 err = serio_open(serio, drv); 171 err = serio_open(serio, drv);
180 if (err) { 172 if (err)
181 serio_set_drvdata(serio, NULL); 173 goto fail;
182 kfree(stinger);
183 return err;
184 }
185
186 input_register_device(&stinger->dev);
187
188 printk(KERN_INFO "input: %s on %s\n", stinger_name, serio->phys);
189 174
175 input_register_device(stinger->dev);
190 return 0; 176 return 0;
177
178 fail: serio_set_drvdata(serio, NULL);
179 input_free_device(input_dev);
180 kfree(stinger);
181 return err;
191} 182}
192 183
193/* 184/*
diff --git a/drivers/input/joystick/tmdc.c b/drivers/input/joystick/tmdc.c
index 7431efc4330e..3a7d1bb46472 100644
--- a/drivers/input/joystick/tmdc.c
+++ b/drivers/input/joystick/tmdc.c
@@ -63,37 +63,70 @@ MODULE_LICENSE("GPL");
63#define TMDC_ABS_HAT 4 63#define TMDC_ABS_HAT 4
64#define TMDC_BTN 16 64#define TMDC_BTN 16
65 65
66static unsigned char tmdc_byte_a[16] = { 0, 1, 3, 4, 6, 7 }; 66static const unsigned char tmdc_byte_a[16] = { 0, 1, 3, 4, 6, 7 };
67static unsigned char tmdc_byte_d[16] = { 2, 5, 8, 9 }; 67static const unsigned char tmdc_byte_d[16] = { 2, 5, 8, 9 };
68 68
69static signed char tmdc_abs[TMDC_ABS] = 69static const signed char tmdc_abs[TMDC_ABS] =
70 { ABS_X, ABS_Y, ABS_RUDDER, ABS_THROTTLE, ABS_RX, ABS_RY, ABS_RZ }; 70 { ABS_X, ABS_Y, ABS_RUDDER, ABS_THROTTLE, ABS_RX, ABS_RY, ABS_RZ };
71static signed char tmdc_abs_hat[TMDC_ABS_HAT] = 71static const signed char tmdc_abs_hat[TMDC_ABS_HAT] =
72 { ABS_HAT0X, ABS_HAT0Y, ABS_HAT1X, ABS_HAT1Y }; 72 { ABS_HAT0X, ABS_HAT0Y, ABS_HAT1X, ABS_HAT1Y };
73static signed char tmdc_abs_at[TMDC_ABS] = 73static const signed char tmdc_abs_at[TMDC_ABS] =
74 { ABS_X, ABS_Y, ABS_RUDDER, -1, ABS_THROTTLE }; 74 { ABS_X, ABS_Y, ABS_RUDDER, -1, ABS_THROTTLE };
75static signed char tmdc_abs_fm[TMDC_ABS] = 75static const signed char tmdc_abs_fm[TMDC_ABS] =
76 { ABS_RX, ABS_RY, ABS_X, ABS_Y }; 76 { ABS_RX, ABS_RY, ABS_X, ABS_Y };
77 77
78static short tmdc_btn_pad[TMDC_BTN] = 78static const short tmdc_btn_pad[TMDC_BTN] =
79 { BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_START, BTN_SELECT, BTN_TL, BTN_TR }; 79 { BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_START, BTN_SELECT, BTN_TL, BTN_TR };
80static short tmdc_btn_joy[TMDC_BTN] = 80static const short tmdc_btn_joy[TMDC_BTN] =
81 { BTN_TRIGGER, BTN_THUMB, BTN_TOP, BTN_TOP2, BTN_BASE, BTN_BASE2, BTN_THUMB2, BTN_PINKIE, 81 { BTN_TRIGGER, BTN_THUMB, BTN_TOP, BTN_TOP2, BTN_BASE, BTN_BASE2, BTN_THUMB2, BTN_PINKIE,
82 BTN_BASE3, BTN_BASE4, BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z }; 82 BTN_BASE3, BTN_BASE4, BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z };
83static short tmdc_btn_fm[TMDC_BTN] = 83static const short tmdc_btn_fm[TMDC_BTN] =
84 { BTN_TRIGGER, BTN_C, BTN_B, BTN_A, BTN_THUMB, BTN_X, BTN_Y, BTN_Z, BTN_TOP, BTN_TOP2 }; 84 { BTN_TRIGGER, BTN_C, BTN_B, BTN_A, BTN_THUMB, BTN_X, BTN_Y, BTN_Z, BTN_TOP, BTN_TOP2 };
85static short tmdc_btn_at[TMDC_BTN] = 85static const short tmdc_btn_at[TMDC_BTN] =
86 { BTN_TRIGGER, BTN_THUMB2, BTN_PINKIE, BTN_THUMB, BTN_BASE6, BTN_BASE5, BTN_BASE4, 86 { BTN_TRIGGER, BTN_THUMB2, BTN_PINKIE, BTN_THUMB, BTN_BASE6, BTN_BASE5, BTN_BASE4,
87 BTN_BASE3, BTN_BASE2, BTN_BASE }; 87 BTN_BASE3, BTN_BASE2, BTN_BASE };
88 88
89static struct { 89static const struct {
90 int x; 90 int x;
91 int y; 91 int y;
92} tmdc_hat_to_axis[] = {{ 0, 0}, { 1, 0}, { 0,-1}, {-1, 0}, { 0, 1}}; 92} tmdc_hat_to_axis[] = {{ 0, 0}, { 1, 0}, { 0,-1}, {-1, 0}, { 0, 1}};
93 93
94static const struct tmdc_model {
95 unsigned char id;
96 const char *name;
97 char abs;
98 char hats;
99 char btnc[4];
100 char btno[4];
101 const signed char *axes;
102 const short *buttons;
103} tmdc_models[] = {
104 { 1, "ThrustMaster Millenium 3D Inceptor", 6, 2, { 4, 2 }, { 4, 6 }, tmdc_abs, tmdc_btn_joy },
105 { 3, "ThrustMaster Rage 3D Gamepad", 2, 0, { 8, 2 }, { 0, 0 }, tmdc_abs, tmdc_btn_pad },
106 { 4, "ThrustMaster Attack Throttle", 5, 2, { 4, 6 }, { 4, 2 }, tmdc_abs_at, tmdc_btn_at },
107 { 8, "ThrustMaster FragMaster", 4, 0, { 8, 2 }, { 0, 0 }, tmdc_abs_fm, tmdc_btn_fm },
108 { 163, "Thrustmaster Fusion GamePad", 2, 0, { 8, 2 }, { 0, 0 }, tmdc_abs, tmdc_btn_pad },
109 { 0, "Unknown %d-axis, %d-button TM device %d", 0, 0, { 0, 0 }, { 0, 0 }, tmdc_abs, tmdc_btn_joy }
110};
111
112
113struct tmdc_port {
114 struct input_dev *dev;
115 char name[64];
116 char phys[32];
117 int mode;
118 const signed char *abs;
119 const short *btn;
120 unsigned char absc;
121 unsigned char btnc[4];
122 unsigned char btno[4];
123};
124
94struct tmdc { 125struct tmdc {
95 struct gameport *gameport; 126 struct gameport *gameport;
96 struct input_dev dev[2]; 127 struct tmdc_port *port[2];
128#if 0
129 struct input_dev *dev[2];
97 char name[2][64]; 130 char name[2][64];
98 char phys[2][32]; 131 char phys[2][32];
99 int mode[2]; 132 int mode[2];
@@ -102,6 +135,7 @@ struct tmdc {
102 unsigned char absc[2]; 135 unsigned char absc[2];
103 unsigned char btnc[2][4]; 136 unsigned char btnc[2][4];
104 unsigned char btno[2][4]; 137 unsigned char btno[2][4];
138#endif
105 int reads; 139 int reads;
106 int bads; 140 int bads;
107 unsigned char exists; 141 unsigned char exists;
@@ -156,6 +190,50 @@ static int tmdc_read_packet(struct gameport *gameport, unsigned char data[2][TMD
156 return (i[0] == TMDC_MAX_LENGTH) | ((i[1] == TMDC_MAX_LENGTH) << 1); 190 return (i[0] == TMDC_MAX_LENGTH) | ((i[1] == TMDC_MAX_LENGTH) << 1);
157} 191}
158 192
193static int tmdc_parse_packet(struct tmdc_port *port, unsigned char *data)
194{
195 int i, k, l;
196
197 if (data[TMDC_BYTE_ID] != port->mode)
198 return -1;
199
200 for (i = 0; i < port->absc; i++) {
201 if (port->abs[i] < 0)
202 return 0;
203
204 input_report_abs(port->dev, port->abs[i], data[tmdc_byte_a[i]]);
205 }
206
207 switch (port->mode) {
208
209 case TMDC_MODE_M3DI:
210
211 i = tmdc_byte_d[0];
212 input_report_abs(port->dev, ABS_HAT0X, ((data[i] >> 3) & 1) - ((data[i] >> 1) & 1));
213 input_report_abs(port->dev, ABS_HAT0Y, ((data[i] >> 2) & 1) - ( data[i] & 1));
214 break;
215
216 case TMDC_MODE_AT:
217
218 i = tmdc_byte_a[3];
219 input_report_abs(port->dev, ABS_HAT0X, tmdc_hat_to_axis[(data[i] - 141) / 25].x);
220 input_report_abs(port->dev, ABS_HAT0Y, tmdc_hat_to_axis[(data[i] - 141) / 25].y);
221 break;
222
223 }
224
225 for (k = l = 0; k < 4; k++) {
226 for (i = 0; i < port->btnc[k]; i++)
227 input_report_key(port->dev, port->btn[i + l],
228 ((data[tmdc_byte_d[k]] >> (i + port->btno[k])) & 1));
229 l += port->btnc[k];
230 }
231
232 input_sync(port->dev);
233
234 return 0;
235}
236
159/* 237/*
160 * tmdc_poll() reads and analyzes ThrustMaster joystick data. 238 * tmdc_poll() reads and analyzes ThrustMaster joystick data.
161 */ 239 */
@@ -164,57 +242,21 @@ static void tmdc_poll(struct gameport *gameport)
164{ 242{
165 unsigned char data[2][TMDC_MAX_LENGTH]; 243 unsigned char data[2][TMDC_MAX_LENGTH];
166 struct tmdc *tmdc = gameport_get_drvdata(gameport); 244 struct tmdc *tmdc = gameport_get_drvdata(gameport);
167 struct input_dev *dev;
168 unsigned char r, bad = 0; 245 unsigned char r, bad = 0;
169 int i, j, k, l; 246 int i;
170 247
171 tmdc->reads++; 248 tmdc->reads++;
172 249
173 if ((r = tmdc_read_packet(tmdc->gameport, data)) != tmdc->exists) 250 if ((r = tmdc_read_packet(tmdc->gameport, data)) != tmdc->exists)
174 bad = 1; 251 bad = 1;
175 else 252 else {
176 253 for (i = 0; i < 2; i++) {
177 for (j = 0; j < 2; j++) 254 if (r & (1 << i) & tmdc->exists) {
178 if (r & (1 << j) & tmdc->exists) {
179
180 if (data[j][TMDC_BYTE_ID] != tmdc->mode[j]) {
181 bad = 1;
182 continue;
183 }
184
185 dev = tmdc->dev + j;
186
187 for (i = 0; i < tmdc->absc[j]; i++) {
188 if (tmdc->abs[j][i] < 0) continue;
189 input_report_abs(dev, tmdc->abs[j][i], data[j][tmdc_byte_a[i]]);
190 }
191
192 switch (tmdc->mode[j]) {
193 255
194 case TMDC_MODE_M3DI: 256 if (tmdc_parse_packet(tmdc->port[i], data[i]))
195 257 bad = 1;
196 i = tmdc_byte_d[0];
197 input_report_abs(dev, ABS_HAT0X, ((data[j][i] >> 3) & 1) - ((data[j][i] >> 1) & 1));
198 input_report_abs(dev, ABS_HAT0Y, ((data[j][i] >> 2) & 1) - ( data[j][i] & 1));
199 break;
200
201 case TMDC_MODE_AT:
202
203 i = tmdc_byte_a[3];
204 input_report_abs(dev, ABS_HAT0X, tmdc_hat_to_axis[(data[j][i] - 141) / 25].x);
205 input_report_abs(dev, ABS_HAT0Y, tmdc_hat_to_axis[(data[j][i] - 141) / 25].y);
206 break;
207
208 }
209
210 for (k = l = 0; k < 4; k++) {
211 for (i = 0; i < tmdc->btnc[j][k]; i++)
212 input_report_key(dev, tmdc->btn[j][i + l],
213 ((data[j][tmdc_byte_d[k]] >> (i + tmdc->btno[j][k])) & 1));
214 l += tmdc->btnc[j][k];
215 } 258 }
216 259 }
217 input_sync(dev);
218 } 260 }
219 261
220 tmdc->bads += bad; 262 tmdc->bads += bad;
@@ -235,31 +277,89 @@ static void tmdc_close(struct input_dev *dev)
235 gameport_stop_polling(tmdc->gameport); 277 gameport_stop_polling(tmdc->gameport);
236} 278}
237 279
280static int tmdc_setup_port(struct tmdc *tmdc, int idx, unsigned char *data)
281{
282 const struct tmdc_model *model;
283 struct tmdc_port *port;
284 struct input_dev *input_dev;
285 int i, j, b = 0;
286
287 tmdc->port[idx] = port = kzalloc(sizeof (struct tmdc_port), GFP_KERNEL);
288 input_dev = input_allocate_device();
289 if (!port || !input_dev) {
290 kfree(port);
291 input_free_device(input_dev);
292 return -ENOMEM;
293 }
294
295 port->mode = data[TMDC_BYTE_ID];
296
297 for (model = tmdc_models; model->id && model->id != port->mode; model++)
298 /* empty */;
299
300 port->abs = model->axes;
301 port->btn = model->buttons;
302
303 if (!model->id) {
304 port->absc = data[TMDC_BYTE_DEF] >> 4;
305 for (i = 0; i < 4; i++)
306 port->btnc[i] = i < (data[TMDC_BYTE_DEF] & 0xf) ? 8 : 0;
307 } else {
308 port->absc = model->abs;
309 for (i = 0; i < 4; i++)
310 port->btnc[i] = model->btnc[i];
311 }
312
313 for (i = 0; i < 4; i++)
314 port->btno[i] = model->btno[i];
315
316 snprintf(port->name, sizeof(port->name), model->name,
317 port->absc, (data[TMDC_BYTE_DEF] & 0xf) << 3, port->mode);
318 snprintf(port->phys, sizeof(port->phys), "%s/input%d", tmdc->gameport->phys, i);
319
320 port->dev = input_dev;
321
322 input_dev->name = port->name;
323 input_dev->phys = port->phys;
324 input_dev->id.bustype = BUS_GAMEPORT;
325 input_dev->id.vendor = GAMEPORT_ID_VENDOR_THRUSTMASTER;
326 input_dev->id.product = model->id;
327 input_dev->id.version = 0x0100;
328 input_dev->cdev.dev = &tmdc->gameport->dev;
329 input_dev->private = tmdc;
330
331 input_dev->open = tmdc_open;
332 input_dev->close = tmdc_close;
333
334 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
335
336 for (i = 0; i < port->absc && i < TMDC_ABS; i++)
337 if (port->abs[i] >= 0)
338 input_set_abs_params(input_dev, port->abs[i], 8, 248, 2, 4);
339
340 for (i = 0; i < model->hats && i < TMDC_ABS_HAT; i++)
341 input_set_abs_params(input_dev, tmdc_abs_hat[i], -1, 1, 0, 0);
342
343 for (i = 0; i < 4; i++) {
344 for (j = 0; j < port->btnc[i] && j < TMDC_BTN; j++)
345 set_bit(port->btn[j + b], input_dev->keybit);
346 b += port->btnc[i];
347 }
348
349 input_register_device(port->dev);
350
351 return 0;
352}
353
238/* 354/*
239 * tmdc_probe() probes for ThrustMaster type joysticks. 355 * tmdc_probe() probes for ThrustMaster type joysticks.
240 */ 356 */
241 357
242static int tmdc_connect(struct gameport *gameport, struct gameport_driver *drv) 358static int tmdc_connect(struct gameport *gameport, struct gameport_driver *drv)
243{ 359{
244 static struct models {
245 unsigned char id;
246 char *name;
247 char abs;
248 char hats;
249 char btnc[4];
250 char btno[4];
251 signed char *axes;
252 short *buttons;
253 } models[] = { { 1, "ThrustMaster Millenium 3D Inceptor", 6, 2, { 4, 2 }, { 4, 6 }, tmdc_abs, tmdc_btn_joy },
254 { 3, "ThrustMaster Rage 3D Gamepad", 2, 0, { 8, 2 }, { 0, 0 }, tmdc_abs, tmdc_btn_pad },
255 { 4, "ThrustMaster Attack Throttle", 5, 2, { 4, 6 }, { 4, 2 }, tmdc_abs_at, tmdc_btn_at },
256 { 8, "ThrustMaster FragMaster", 4, 0, { 8, 2 }, { 0, 0 }, tmdc_abs_fm, tmdc_btn_fm },
257 { 163, "Thrustmaster Fusion GamePad", 2, 0, { 8, 2 }, { 0, 0 }, tmdc_abs, tmdc_btn_pad },
258 { 0, "Unknown %d-axis, %d-button TM device %d", 0, 0, { 0, 0 }, { 0, 0 }, tmdc_abs, tmdc_btn_joy }};
259
260 unsigned char data[2][TMDC_MAX_LENGTH]; 360 unsigned char data[2][TMDC_MAX_LENGTH];
261 struct tmdc *tmdc; 361 struct tmdc *tmdc;
262 int i, j, k, l, m; 362 int i;
263 int err; 363 int err;
264 364
265 if (!(tmdc = kzalloc(sizeof(struct tmdc), GFP_KERNEL))) 365 if (!(tmdc = kzalloc(sizeof(struct tmdc), GFP_KERNEL)))
@@ -281,68 +381,25 @@ static int tmdc_connect(struct gameport *gameport, struct gameport_driver *drv)
281 gameport_set_poll_handler(gameport, tmdc_poll); 381 gameport_set_poll_handler(gameport, tmdc_poll);
282 gameport_set_poll_interval(gameport, 20); 382 gameport_set_poll_interval(gameport, 20);
283 383
284 for (j = 0; j < 2; j++) 384 for (i = 0; i < 2; i++) {
285 if (tmdc->exists & (1 << j)) { 385 if (tmdc->exists & (1 << i)) {
286 386
287 tmdc->mode[j] = data[j][TMDC_BYTE_ID]; 387 err = tmdc_setup_port(tmdc, i, data[i]);
288 388 if (err)
289 for (m = 0; models[m].id && models[m].id != tmdc->mode[j]; m++); 389 goto fail3;
290
291 tmdc->abs[j] = models[m].axes;
292 tmdc->btn[j] = models[m].buttons;
293
294 if (!models[m].id) {
295 models[m].abs = data[j][TMDC_BYTE_DEF] >> 4;
296 for (k = 0; k < 4; k++)
297 models[m].btnc[k] = k < (data[j][TMDC_BYTE_DEF] & 0xf) ? 8 : 0;
298 }
299
300 tmdc->absc[j] = models[m].abs;
301 for (k = 0; k < 4; k++) {
302 tmdc->btnc[j][k] = models[m].btnc[k];
303 tmdc->btno[j][k] = models[m].btno[k];
304 }
305
306 sprintf(tmdc->name[j], models[m].name, models[m].abs,
307 (data[j][TMDC_BYTE_DEF] & 0xf) << 3, tmdc->mode[j]);
308
309 sprintf(tmdc->phys[j], "%s/input%d", gameport->phys, j);
310
311 tmdc->dev[j].private = tmdc;
312 tmdc->dev[j].open = tmdc_open;
313 tmdc->dev[j].close = tmdc_close;
314
315 tmdc->dev[j].name = tmdc->name[j];
316 tmdc->dev[j].phys = tmdc->phys[j];
317 tmdc->dev[j].id.bustype = BUS_GAMEPORT;
318 tmdc->dev[j].id.vendor = GAMEPORT_ID_VENDOR_THRUSTMASTER;
319 tmdc->dev[j].id.product = models[m].id;
320 tmdc->dev[j].id.version = 0x0100;
321
322 tmdc->dev[j].evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
323
324 for (i = 0; i < models[m].abs && i < TMDC_ABS; i++)
325 if (tmdc->abs[j][i] >= 0)
326 input_set_abs_params(&tmdc->dev[j], tmdc->abs[j][i], 8, 248, 2, 4);
327
328 for (i = 0; i < models[m].hats && i < TMDC_ABS_HAT; i++)
329 input_set_abs_params(&tmdc->dev[j], tmdc_abs_hat[i], -1, 1, 0, 0);
330
331
332 for (k = l = 0; k < 4; k++) {
333 for (i = 0; i < models[m].btnc[k] && i < TMDC_BTN; i++)
334 set_bit(tmdc->btn[j][i + l], tmdc->dev[j].keybit);
335 l += models[m].btnc[k];
336 }
337
338 input_register_device(tmdc->dev + j);
339 printk(KERN_INFO "input: %s on %s\n", tmdc->name[j], gameport->phys);
340 } 390 }
391 }
341 392
342 return 0; 393 return 0;
343 394
344fail2: gameport_close(gameport); 395 fail3: while (--i >= 0) {
345fail1: gameport_set_drvdata(gameport, NULL); 396 if (tmdc->port[i]) {
397 input_unregister_device(tmdc->port[i]->dev);
398 kfree(tmdc->port[i]);
399 }
400 }
401 fail2: gameport_close(gameport);
402 fail1: gameport_set_drvdata(gameport, NULL);
346 kfree(tmdc); 403 kfree(tmdc);
347 return err; 404 return err;
348} 405}
@@ -352,9 +409,12 @@ static void tmdc_disconnect(struct gameport *gameport)
352 struct tmdc *tmdc = gameport_get_drvdata(gameport); 409 struct tmdc *tmdc = gameport_get_drvdata(gameport);
353 int i; 410 int i;
354 411
355 for (i = 0; i < 2; i++) 412 for (i = 0; i < 2; i++) {
356 if (tmdc->exists & (1 << i)) 413 if (tmdc->port[i]) {
357 input_unregister_device(tmdc->dev + i); 414 input_unregister_device(tmdc->port[i]->dev);
415 kfree(tmdc->port[i]);
416 }
417 }
358 gameport_close(gameport); 418 gameport_close(gameport);
359 gameport_set_drvdata(gameport, NULL); 419 gameport_set_drvdata(gameport, NULL);
360 kfree(tmdc); 420 kfree(tmdc);
diff --git a/drivers/input/joystick/turbografx.c b/drivers/input/joystick/turbografx.c
index 0c5b9c8297cd..7e9764937d06 100644
--- a/drivers/input/joystick/turbografx.c
+++ b/drivers/input/joystick/turbografx.c
@@ -42,19 +42,21 @@ MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
42MODULE_DESCRIPTION("TurboGraFX parallel port interface driver"); 42MODULE_DESCRIPTION("TurboGraFX parallel port interface driver");
43MODULE_LICENSE("GPL"); 43MODULE_LICENSE("GPL");
44 44
45static int tgfx[] __initdata = { -1, 0, 0, 0, 0, 0, 0, 0 }; 45#define TGFX_MAX_PORTS 3
46static int tgfx_nargs __initdata = 0; 46#define TGFX_MAX_DEVICES 7
47module_param_array_named(map, tgfx, int, &tgfx_nargs, 0);
48MODULE_PARM_DESC(map, "Describes first set of devices (<parport#>,<js1>,<js2>,..<js7>");
49 47
50static int tgfx_2[] __initdata = { -1, 0, 0, 0, 0, 0, 0, 0 }; 48struct tgfx_config {
51static int tgfx_nargs_2 __initdata = 0; 49 int args[TGFX_MAX_DEVICES + 1];
52module_param_array_named(map2, tgfx_2, int, &tgfx_nargs_2, 0); 50 int nargs;
53MODULE_PARM_DESC(map2, "Describes second set of devices"); 51};
52
53static struct tgfx_config tgfx[TGFX_MAX_PORTS] __initdata;
54 54
55static int tgfx_3[] __initdata = { -1, 0, 0, 0, 0, 0, 0, 0 }; 55module_param_array_named(map, tgfx[0].args, int, &tgfx[0].nargs, 0);
56static int tgfx_nargs_3 __initdata = 0; 56MODULE_PARM_DESC(map, "Describes first set of devices (<parport#>,<js1>,<js2>,..<js7>");
57module_param_array_named(map3, tgfx_3, int, &tgfx_nargs_3, 0); 57module_param_array_named(map2, tgfx[1].args, int, &tgfx[1].nargs, 0);
58MODULE_PARM_DESC(map2, "Describes second set of devices");
59module_param_array_named(map3, tgfx[2].args, int, &tgfx[2].nargs, 0);
58MODULE_PARM_DESC(map3, "Describes third set of devices"); 60MODULE_PARM_DESC(map3, "Describes third set of devices");
59 61
60__obsolete_setup("tgfx="); 62__obsolete_setup("tgfx=");
@@ -75,17 +77,17 @@ __obsolete_setup("tgfx_3=");
75#define TGFX_TOP2 0x08 77#define TGFX_TOP2 0x08
76 78
77static int tgfx_buttons[] = { BTN_TRIGGER, BTN_THUMB, BTN_THUMB2, BTN_TOP, BTN_TOP2 }; 79static int tgfx_buttons[] = { BTN_TRIGGER, BTN_THUMB, BTN_THUMB2, BTN_TOP, BTN_TOP2 };
78static char *tgfx_name = "TurboGraFX Multisystem joystick";
79 80
80static struct tgfx { 81static struct tgfx {
81 struct pardevice *pd; 82 struct pardevice *pd;
82 struct timer_list timer; 83 struct timer_list timer;
83 struct input_dev dev[7]; 84 struct input_dev *dev[TGFX_MAX_DEVICES];
84 char phys[7][32]; 85 char name[TGFX_MAX_DEVICES][64];
86 char phys[TGFX_MAX_DEVICES][32];
85 int sticks; 87 int sticks;
86 int used; 88 int used;
87 struct semaphore sem; 89 struct semaphore sem;
88} *tgfx_base[3]; 90} *tgfx_base[TGFX_MAX_PORTS];
89 91
90/* 92/*
91 * tgfx_timer() reads and analyzes TurboGraFX joystick data. 93 * tgfx_timer() reads and analyzes TurboGraFX joystick data.
@@ -100,7 +102,7 @@ static void tgfx_timer(unsigned long private)
100 for (i = 0; i < 7; i++) 102 for (i = 0; i < 7; i++)
101 if (tgfx->sticks & (1 << i)) { 103 if (tgfx->sticks & (1 << i)) {
102 104
103 dev = tgfx->dev + i; 105 dev = tgfx->dev[i];
104 106
105 parport_write_data(tgfx->pd->port, ~(1 << i)); 107 parport_write_data(tgfx->pd->port, ~(1 << i));
106 data1 = parport_read_status(tgfx->pd->port) ^ 0x7f; 108 data1 = parport_read_status(tgfx->pd->port) ^ 0x7f;
@@ -153,118 +155,165 @@ static void tgfx_close(struct input_dev *dev)
153 up(&tgfx->sem); 155 up(&tgfx->sem);
154} 156}
155 157
158
159
156/* 160/*
157 * tgfx_probe() probes for tg gamepads. 161 * tgfx_probe() probes for tg gamepads.
158 */ 162 */
159 163
160static struct tgfx __init *tgfx_probe(int *config, int nargs) 164static struct tgfx __init *tgfx_probe(int parport, int *n_buttons, int n_devs)
161{ 165{
162 struct tgfx *tgfx; 166 struct tgfx *tgfx;
167 struct input_dev *input_dev;
163 struct parport *pp; 168 struct parport *pp;
169 struct pardevice *pd;
164 int i, j; 170 int i, j;
171 int err;
165 172
166 if (config[0] < 0) 173 pp = parport_find_number(parport);
167 return NULL;
168
169 if (nargs < 2) {
170 printk(KERN_ERR "turbografx.c: at least one joystick must be specified\n");
171 return NULL;
172 }
173
174 pp = parport_find_number(config[0]);
175
176 if (!pp) { 174 if (!pp) {
177 printk(KERN_ERR "turbografx.c: no such parport\n"); 175 printk(KERN_ERR "turbografx.c: no such parport\n");
178 return NULL; 176 err = -EINVAL;
177 goto err_out;
179 } 178 }
180 179
181 if (!(tgfx = kzalloc(sizeof(struct tgfx), GFP_KERNEL))) { 180 pd = parport_register_device(pp, "turbografx", NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL);
182 parport_put_port(pp); 181 if (!pd) {
183 return NULL; 182 printk(KERN_ERR "turbografx.c: parport busy already - lp.o loaded?\n");
183 err = -EBUSY;
184 goto err_put_pp;
184 } 185 }
185 186
186 init_MUTEX(&tgfx->sem); 187 tgfx = kzalloc(sizeof(struct tgfx), GFP_KERNEL);
187 188 if (!tgfx) {
188 tgfx->pd = parport_register_device(pp, "turbografx", NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL); 189 printk(KERN_ERR "turbografx.c: Not enough memory\n");
189 190 err = -ENOMEM;
190 parport_put_port(pp); 191 goto err_unreg_pardev;
191
192 if (!tgfx->pd) {
193 printk(KERN_ERR "turbografx.c: parport busy already - lp.o loaded?\n");
194 kfree(tgfx);
195 return NULL;
196 } 192 }
197 193
194 init_MUTEX(&tgfx->sem);
195 tgfx->pd = pd;
198 init_timer(&tgfx->timer); 196 init_timer(&tgfx->timer);
199 tgfx->timer.data = (long) tgfx; 197 tgfx->timer.data = (long) tgfx;
200 tgfx->timer.function = tgfx_timer; 198 tgfx->timer.function = tgfx_timer;
201 199
202 tgfx->sticks = 0; 200 for (i = 0; i < n_devs; i++) {
201 if (n_buttons[i] < 1)
202 continue;
203 203
204 for (i = 0; i < nargs - 1; i++) 204 if (n_buttons[i] > 6) {
205 if (config[i+1] > 0 && config[i+1] < 6) { 205 printk(KERN_ERR "turbografx.c: Invalid number of buttons %d\n", n_buttons[i]);
206 206 err = -EINVAL;
207 tgfx->sticks |= (1 << i); 207 goto err_free_devs;
208 }
208 209
209 tgfx->dev[i].private = tgfx; 210 tgfx->dev[i] = input_dev = input_allocate_device();
210 tgfx->dev[i].open = tgfx_open; 211 if (!input_dev) {
211 tgfx->dev[i].close = tgfx_close; 212 printk(KERN_ERR "turbografx.c: Not enough memory for input device\n");
213 err = -ENOMEM;
214 goto err_free_devs;
215 }
212 216
213 sprintf(tgfx->phys[i], "%s/input0", tgfx->pd->port->name); 217 tgfx->sticks |= (1 << i);
218 snprintf(tgfx->name[i], sizeof(tgfx->name[i]),
219 "TurboGraFX %d-button Multisystem joystick", n_buttons[i]);
220 snprintf(tgfx->phys[i], sizeof(tgfx->phys[i]),
221 "%s/input%d", tgfx->pd->port->name, i);
214 222
215 tgfx->dev[i].name = tgfx_name; 223 input_dev->name = tgfx->name[i];
216 tgfx->dev[i].phys = tgfx->phys[i]; 224 input_dev->phys = tgfx->phys[i];
217 tgfx->dev[i].id.bustype = BUS_PARPORT; 225 input_dev->id.bustype = BUS_PARPORT;
218 tgfx->dev[i].id.vendor = 0x0003; 226 input_dev->id.vendor = 0x0003;
219 tgfx->dev[i].id.product = config[i+1]; 227 input_dev->id.product = n_buttons[i];
220 tgfx->dev[i].id.version = 0x0100; 228 input_dev->id.version = 0x0100;
221 229
222 tgfx->dev[i].evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 230 input_dev->private = tgfx;
223 tgfx->dev[i].absbit[0] = BIT(ABS_X) | BIT(ABS_Y); 231 input_dev->open = tgfx_open;
232 input_dev->close = tgfx_close;
224 233
225 for (j = 0; j < config[i+1]; j++) 234 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
226 set_bit(tgfx_buttons[j], tgfx->dev[i].keybit); 235 input_set_abs_params(input_dev, ABS_X, -1, 1, 0, 0);
236 input_set_abs_params(input_dev, ABS_Y, -1, 1, 0, 0);
227 237
228 tgfx->dev[i].absmin[ABS_X] = -1; tgfx->dev[i].absmax[ABS_X] = 1; 238 for (j = 0; j < n_buttons[i]; j++)
229 tgfx->dev[i].absmin[ABS_Y] = -1; tgfx->dev[i].absmax[ABS_Y] = 1; 239 set_bit(tgfx_buttons[j], input_dev->keybit);
230 240
231 input_register_device(tgfx->dev + i); 241 input_register_device(tgfx->dev[i]);
232 printk(KERN_INFO "input: %d-button Multisystem joystick on %s\n", 242 }
233 config[i+1], tgfx->pd->port->name);
234 }
235 243
236 if (!tgfx->sticks) { 244 if (!tgfx->sticks) {
237 parport_unregister_device(tgfx->pd); 245 printk(KERN_ERR "turbografx.c: No valid devices specified\n");
238 kfree(tgfx); 246 err = -EINVAL;
239 return NULL; 247 goto err_free_tgfx;
240 } 248 }
241 249
242 return tgfx; 250 return tgfx;
251
252 err_free_devs:
253 while (--i >= 0)
254 input_unregister_device(tgfx->dev[i]);
255 err_free_tgfx:
256 kfree(tgfx);
257 err_unreg_pardev:
258 parport_unregister_device(pd);
259 err_put_pp:
260 parport_put_port(pp);
261 err_out:
262 return ERR_PTR(err);
263}
264
265static void __exit tgfx_remove(struct tgfx *tgfx)
266{
267 int i;
268
269 for (i = 0; i < TGFX_MAX_DEVICES; i++)
270 if (tgfx->dev[i])
271 input_unregister_device(tgfx->dev[i]);
272 parport_unregister_device(tgfx->pd);
273 kfree(tgfx);
243} 274}
244 275
245static int __init tgfx_init(void) 276static int __init tgfx_init(void)
246{ 277{
247 tgfx_base[0] = tgfx_probe(tgfx, tgfx_nargs); 278 int i;
248 tgfx_base[1] = tgfx_probe(tgfx_2, tgfx_nargs_2); 279 int have_dev = 0;
249 tgfx_base[2] = tgfx_probe(tgfx_3, tgfx_nargs_3); 280 int err = 0;
281
282 for (i = 0; i < TGFX_MAX_PORTS; i++) {
283 if (tgfx[i].nargs == 0 || tgfx[i].args[0] < 0)
284 continue;
285
286 if (tgfx[i].nargs < 2) {
287 printk(KERN_ERR "turbografx.c: at least one joystick must be specified\n");
288 err = -EINVAL;
289 break;
290 }
291
292 tgfx_base[i] = tgfx_probe(tgfx[i].args[0], tgfx[i].args + 1, tgfx[i].nargs - 1);
293 if (IS_ERR(tgfx_base[i])) {
294 err = PTR_ERR(tgfx_base[i]);
295 break;
296 }
297
298 have_dev = 1;
299 }
250 300
251 if (tgfx_base[0] || tgfx_base[1] || tgfx_base[2]) 301 if (err) {
252 return 0; 302 while (--i >= 0)
303 tgfx_remove(tgfx_base[i]);
304 return err;
305 }
253 306
254 return -ENODEV; 307 return have_dev ? 0 : -ENODEV;
255} 308}
256 309
257static void __exit tgfx_exit(void) 310static void __exit tgfx_exit(void)
258{ 311{
259 int i, j; 312 int i;
260 313
261 for (i = 0; i < 3; i++) 314 for (i = 0; i < TGFX_MAX_PORTS; i++)
262 if (tgfx_base[i]) { 315 if (tgfx_base[i])
263 for (j = 0; j < 7; j++) 316 tgfx_remove(tgfx_base[i]);
264 if (tgfx_base[i]->sticks & (1 << j))
265 input_unregister_device(tgfx_base[i]->dev + j);
266 parport_unregister_device(tgfx_base[i]->pd);
267 }
268} 317}
269 318
270module_init(tgfx_init); 319module_init(tgfx_init);
diff --git a/drivers/input/joystick/twidjoy.c b/drivers/input/joystick/twidjoy.c
index 0379bc166525..cd3a1e742a30 100644
--- a/drivers/input/joystick/twidjoy.c
+++ b/drivers/input/joystick/twidjoy.c
@@ -69,8 +69,6 @@ MODULE_LICENSE("GPL");
69 69
70#define TWIDJOY_MAX_LENGTH 5 70#define TWIDJOY_MAX_LENGTH 5
71 71
72static char *twidjoy_name = "Handykey Twiddler";
73
74static struct twidjoy_button_spec { 72static struct twidjoy_button_spec {
75 int bitshift; 73 int bitshift;
76 int bitmask; 74 int bitmask;
@@ -95,7 +93,7 @@ twidjoy_buttons[] = {
95 */ 93 */
96 94
97struct twidjoy { 95struct twidjoy {
98 struct input_dev dev; 96 struct input_dev *dev;
99 int idx; 97 int idx;
100 unsigned char data[TWIDJOY_MAX_LENGTH]; 98 unsigned char data[TWIDJOY_MAX_LENGTH];
101 char phys[32]; 99 char phys[32];
@@ -108,37 +106,33 @@ struct twidjoy {
108 106
109static void twidjoy_process_packet(struct twidjoy *twidjoy, struct pt_regs *regs) 107static void twidjoy_process_packet(struct twidjoy *twidjoy, struct pt_regs *regs)
110{ 108{
111 if (twidjoy->idx == TWIDJOY_MAX_LENGTH) { 109 struct input_dev *dev = twidjoy->dev;
112 struct input_dev *dev = &twidjoy->dev; 110 unsigned char *data = twidjoy->data;
113 unsigned char *data = twidjoy->data; 111 struct twidjoy_button_spec *bp;
114 struct twidjoy_button_spec *bp; 112 int button_bits, abs_x, abs_y;
115 int button_bits, abs_x, abs_y;
116
117 button_bits = ((data[1] & 0x7f) << 7) | (data[0] & 0x7f);
118 113
119 input_regs(dev, regs); 114 button_bits = ((data[1] & 0x7f) << 7) | (data[0] & 0x7f);
120 115
121 for (bp = twidjoy_buttons; bp->bitmask; bp++) { 116 input_regs(dev, regs);
122 int value = (button_bits & (bp->bitmask << bp->bitshift)) >> bp->bitshift;
123 int i;
124 117
125 for (i = 0; i < bp->bitmask; i++) 118 for (bp = twidjoy_buttons; bp->bitmask; bp++) {
126 input_report_key(dev, bp->buttons[i], i+1 == value); 119 int value = (button_bits & (bp->bitmask << bp->bitshift)) >> bp->bitshift;
127 } 120 int i;
128 121
129 abs_x = ((data[4] & 0x07) << 5) | ((data[3] & 0x7C) >> 2); 122 for (i = 0; i < bp->bitmask; i++)
130 if (data[4] & 0x08) abs_x -= 256; 123 input_report_key(dev, bp->buttons[i], i+1 == value);
124 }
131 125
132 abs_y = ((data[3] & 0x01) << 7) | ((data[2] & 0x7F) >> 0); 126 abs_x = ((data[4] & 0x07) << 5) | ((data[3] & 0x7C) >> 2);
133 if (data[3] & 0x02) abs_y -= 256; 127 if (data[4] & 0x08) abs_x -= 256;
134 128
135 input_report_abs(dev, ABS_X, -abs_x); 129 abs_y = ((data[3] & 0x01) << 7) | ((data[2] & 0x7F) >> 0);
136 input_report_abs(dev, ABS_Y, +abs_y); 130 if (data[3] & 0x02) abs_y -= 256;
137 131
138 input_sync(dev); 132 input_report_abs(dev, ABS_X, -abs_x);
139 } 133 input_report_abs(dev, ABS_Y, +abs_y);
140 134
141 return; 135 input_sync(dev);
142} 136}
143 137
144/* 138/*
@@ -179,9 +173,9 @@ static void twidjoy_disconnect(struct serio *serio)
179{ 173{
180 struct twidjoy *twidjoy = serio_get_drvdata(serio); 174 struct twidjoy *twidjoy = serio_get_drvdata(serio);
181 175
182 input_unregister_device(&twidjoy->dev);
183 serio_close(serio); 176 serio_close(serio);
184 serio_set_drvdata(serio, NULL); 177 serio_set_drvdata(serio, NULL);
178 input_unregister_device(twidjoy->dev);
185 kfree(twidjoy); 179 kfree(twidjoy);
186} 180}
187 181
@@ -195,59 +189,49 @@ static int twidjoy_connect(struct serio *serio, struct serio_driver *drv)
195{ 189{
196 struct twidjoy_button_spec *bp; 190 struct twidjoy_button_spec *bp;
197 struct twidjoy *twidjoy; 191 struct twidjoy *twidjoy;
192 struct input_dev *input_dev;
193 int err = -ENOMEM;
198 int i; 194 int i;
199 int err;
200
201 if (!(twidjoy = kmalloc(sizeof(struct twidjoy), GFP_KERNEL)))
202 return -ENOMEM;
203 195
204 memset(twidjoy, 0, sizeof(struct twidjoy)); 196 twidjoy = kzalloc(sizeof(struct twidjoy), GFP_KERNEL);
197 input_dev = input_allocate_device();
198 if (!twidjoy || !input_dev)
199 goto fail;
205 200
201 twidjoy->dev = input_dev;
206 sprintf(twidjoy->phys, "%s/input0", serio->phys); 202 sprintf(twidjoy->phys, "%s/input0", serio->phys);
207 203
208 init_input_dev(&twidjoy->dev); 204 input_dev->name = "Handykey Twiddler";
209 twidjoy->dev.name = twidjoy_name; 205 input_dev->phys = twidjoy->phys;
210 twidjoy->dev.phys = twidjoy->phys; 206 input_dev->id.bustype = BUS_RS232;
211 twidjoy->dev.id.bustype = BUS_RS232; 207 input_dev->id.vendor = SERIO_TWIDJOY;
212 twidjoy->dev.id.vendor = SERIO_TWIDJOY; 208 input_dev->id.product = 0x0001;
213 twidjoy->dev.id.product = 0x0001; 209 input_dev->id.version = 0x0100;
214 twidjoy->dev.id.version = 0x0100; 210 input_dev->cdev.dev = &serio->dev;
215 twidjoy->dev.dev = &serio->dev; 211 input_dev->private = twidjoy;
216 212
217 twidjoy->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 213 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
218 214 input_dev->absbit[0] = BIT(ABS_X) | BIT(ABS_Y);
219 for (bp = twidjoy_buttons; bp->bitmask; bp++) { 215 input_set_abs_params(input_dev, ABS_X, -50, 50, 4, 4);
216 input_set_abs_params(input_dev, ABS_Y, -50, 50, 4, 4);
217
218 for (bp = twidjoy_buttons; bp->bitmask; bp++)
220 for (i = 0; i < bp->bitmask; i++) 219 for (i = 0; i < bp->bitmask; i++)
221 set_bit(bp->buttons[i], twidjoy->dev.keybit); 220 set_bit(bp->buttons[i], input_dev->keybit);
222 }
223
224 twidjoy->dev.absbit[0] = BIT(ABS_X) | BIT(ABS_Y);
225
226 for (i = 0; i < 2; i++) {
227 twidjoy->dev.absmax[ABS_X+i] = 50;
228 twidjoy->dev.absmin[ABS_X+i] = -50;
229
230 /* TODO: arndt 20010708: Are these values appropriate? */
231 twidjoy->dev.absfuzz[ABS_X+i] = 4;
232 twidjoy->dev.absflat[ABS_X+i] = 4;
233 }
234
235 twidjoy->dev.private = twidjoy;
236 221
237 serio_set_drvdata(serio, twidjoy); 222 serio_set_drvdata(serio, twidjoy);
238 223
239 err = serio_open(serio, drv); 224 err = serio_open(serio, drv);
240 if (err) { 225 if (err)
241 serio_set_drvdata(serio, NULL); 226 goto fail;
242 kfree(twidjoy);
243 return err;
244 }
245
246 input_register_device(&twidjoy->dev);
247
248 printk(KERN_INFO "input: %s on %s\n", twidjoy_name, serio->phys);
249 227
228 input_register_device(twidjoy->dev);
250 return 0; 229 return 0;
230
231 fail: serio_set_drvdata(serio, NULL);
232 input_free_device(input_dev);
233 kfree(twidjoy);
234 return err;
251} 235}
252 236
253/* 237/*
diff --git a/drivers/input/joystick/warrior.c b/drivers/input/joystick/warrior.c
index 6976a219504c..99a642d2a1fe 100644
--- a/drivers/input/joystick/warrior.c
+++ b/drivers/input/joystick/warrior.c
@@ -47,14 +47,13 @@ MODULE_LICENSE("GPL");
47 47
48#define WARRIOR_MAX_LENGTH 16 48#define WARRIOR_MAX_LENGTH 16
49static char warrior_lengths[] = { 0, 4, 12, 3, 4, 4, 0, 0 }; 49static char warrior_lengths[] = { 0, 4, 12, 3, 4, 4, 0, 0 };
50static char *warrior_name = "Logitech WingMan Warrior";
51 50
52/* 51/*
53 * Per-Warrior data. 52 * Per-Warrior data.
54 */ 53 */
55 54
56struct warrior { 55struct warrior {
57 struct input_dev dev; 56 struct input_dev *dev;
58 int idx, len; 57 int idx, len;
59 unsigned char data[WARRIOR_MAX_LENGTH]; 58 unsigned char data[WARRIOR_MAX_LENGTH];
60 char phys[32]; 59 char phys[32];
@@ -67,7 +66,7 @@ struct warrior {
67 66
68static void warrior_process_packet(struct warrior *warrior, struct pt_regs *regs) 67static void warrior_process_packet(struct warrior *warrior, struct pt_regs *regs)
69{ 68{
70 struct input_dev *dev = &warrior->dev; 69 struct input_dev *dev = warrior->dev;
71 unsigned char *data = warrior->data; 70 unsigned char *data = warrior->data;
72 71
73 if (!warrior->idx) return; 72 if (!warrior->idx) return;
@@ -131,9 +130,9 @@ static void warrior_disconnect(struct serio *serio)
131{ 130{
132 struct warrior *warrior = serio_get_drvdata(serio); 131 struct warrior *warrior = serio_get_drvdata(serio);
133 132
134 input_unregister_device(&warrior->dev);
135 serio_close(serio); 133 serio_close(serio);
136 serio_set_drvdata(serio, NULL); 134 serio_set_drvdata(serio, NULL);
135 input_unregister_device(warrior->dev);
137 kfree(warrior); 136 kfree(warrior);
138} 137}
139 138
@@ -146,60 +145,48 @@ static void warrior_disconnect(struct serio *serio)
146static int warrior_connect(struct serio *serio, struct serio_driver *drv) 145static int warrior_connect(struct serio *serio, struct serio_driver *drv)
147{ 146{
148 struct warrior *warrior; 147 struct warrior *warrior;
149 int i; 148 struct input_dev *input_dev;
150 int err; 149 int err = -ENOMEM;
151 150
152 if (!(warrior = kmalloc(sizeof(struct warrior), GFP_KERNEL))) 151 warrior = kzalloc(sizeof(struct warrior), GFP_KERNEL);
153 return -ENOMEM; 152 input_dev = input_allocate_device();
154 153 if (!warrior || !input_dev)
155 memset(warrior, 0, sizeof(struct warrior)); 154 goto fail;
156
157 warrior->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REL) | BIT(EV_ABS);
158 warrior->dev.keybit[LONG(BTN_TRIGGER)] = BIT(BTN_TRIGGER) | BIT(BTN_THUMB) | BIT(BTN_TOP) | BIT(BTN_TOP2);
159 warrior->dev.relbit[0] = BIT(REL_DIAL);
160 warrior->dev.absbit[0] = BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_THROTTLE) | BIT(ABS_HAT0X) | BIT(ABS_HAT0Y);
161 155
156 warrior->dev = input_dev;
162 sprintf(warrior->phys, "%s/input0", serio->phys); 157 sprintf(warrior->phys, "%s/input0", serio->phys);
163 158
164 init_input_dev(&warrior->dev); 159 input_dev->name = "Logitech WingMan Warrior";
165 warrior->dev.name = warrior_name; 160 input_dev->phys = warrior->phys;
166 warrior->dev.phys = warrior->phys; 161 input_dev->id.bustype = BUS_RS232;
167 warrior->dev.id.bustype = BUS_RS232; 162 input_dev->id.vendor = SERIO_WARRIOR;
168 warrior->dev.id.vendor = SERIO_WARRIOR; 163 input_dev->id.product = 0x0001;
169 warrior->dev.id.product = 0x0001; 164 input_dev->id.version = 0x0100;
170 warrior->dev.id.version = 0x0100; 165 input_dev->cdev.dev = &serio->dev;
171 warrior->dev.dev = &serio->dev; 166 input_dev->private = warrior;
172 167
173 for (i = 0; i < 2; i++) { 168 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL) | BIT(EV_ABS);
174 warrior->dev.absmax[ABS_X+i] = -64; 169 input_dev->keybit[LONG(BTN_TRIGGER)] = BIT(BTN_TRIGGER) | BIT(BTN_THUMB) | BIT(BTN_TOP) | BIT(BTN_TOP2);
175 warrior->dev.absmin[ABS_X+i] = 64; 170 input_dev->relbit[0] = BIT(REL_DIAL);
176 warrior->dev.absflat[ABS_X+i] = 8; 171 input_set_abs_params(input_dev, ABS_X, -64, 64, 0, 8);
177 } 172 input_set_abs_params(input_dev, ABS_Y, -64, 64, 0, 8);
178 173 input_set_abs_params(input_dev, ABS_THROTTLE, -112, 112, 0, 0);
179 warrior->dev.absmax[ABS_THROTTLE] = -112; 174 input_set_abs_params(input_dev, ABS_HAT0X, -1, 1, 0, 0);
180 warrior->dev.absmin[ABS_THROTTLE] = 112; 175 input_set_abs_params(input_dev, ABS_HAT0X, -1, 1, 0, 0);
181
182 for (i = 0; i < 2; i++) {
183 warrior->dev.absmax[ABS_HAT0X+i] = -1;
184 warrior->dev.absmin[ABS_HAT0X+i] = 1;
185 }
186
187 warrior->dev.private = warrior;
188 176
189 serio_set_drvdata(serio, warrior); 177 serio_set_drvdata(serio, warrior);
190 178
191 err = serio_open(serio, drv); 179 err = serio_open(serio, drv);
192 if (err) { 180 if (err)
193 serio_set_drvdata(serio, NULL); 181 goto fail;
194 kfree(warrior);
195 return err;
196 }
197
198 input_register_device(&warrior->dev);
199
200 printk(KERN_INFO "input: Logitech WingMan Warrior on %s\n", serio->phys);
201 182
183 input_register_device(warrior->dev);
202 return 0; 184 return 0;
185
186 fail: serio_set_drvdata(serio, NULL);
187 input_free_device(input_dev);
188 kfree(warrior);
189 return err;
203} 190}
204 191
205/* 192/*
diff --git a/drivers/input/keyboard/amikbd.c b/drivers/input/keyboard/amikbd.c
index 4e8e8ea214ab..3d63bc1ad322 100644
--- a/drivers/input/keyboard/amikbd.c
+++ b/drivers/input/keyboard/amikbd.c
@@ -155,10 +155,7 @@ static const char *amikbd_messages[8] = {
155 [7] = KERN_WARNING "amikbd: keyboard interrupt\n" 155 [7] = KERN_WARNING "amikbd: keyboard interrupt\n"
156}; 156};
157 157
158static struct input_dev amikbd_dev; 158static struct input_dev *amikbd_dev;
159
160static char *amikbd_name = "Amiga keyboard";
161static char *amikbd_phys = "amikbd/input0";
162 159
163static irqreturn_t amikbd_interrupt(int irq, void *dummy, struct pt_regs *fp) 160static irqreturn_t amikbd_interrupt(int irq, void *dummy, struct pt_regs *fp)
164{ 161{
@@ -176,16 +173,16 @@ static irqreturn_t amikbd_interrupt(int irq, void *dummy, struct pt_regs *fp)
176 173
177 scancode = amikbd_keycode[scancode]; 174 scancode = amikbd_keycode[scancode];
178 175
179 input_regs(&amikbd_dev, fp); 176 input_regs(amikbd_dev, fp);
180 177
181 if (scancode == KEY_CAPSLOCK) { /* CapsLock is a toggle switch key on Amiga */ 178 if (scancode == KEY_CAPSLOCK) { /* CapsLock is a toggle switch key on Amiga */
182 input_report_key(&amikbd_dev, scancode, 1); 179 input_report_key(amikbd_dev, scancode, 1);
183 input_report_key(&amikbd_dev, scancode, 0); 180 input_report_key(amikbd_dev, scancode, 0);
184 input_sync(&amikbd_dev);
185 } else { 181 } else {
186 input_report_key(&amikbd_dev, scancode, down); 182 input_report_key(amikbd_dev, scancode, down);
187 input_sync(&amikbd_dev);
188 } 183 }
184
185 input_sync(amikbd_dev);
189 } else /* scancodes >= 0x78 are error codes */ 186 } else /* scancodes >= 0x78 are error codes */
190 printk(amikbd_messages[scancode - 0x78]); 187 printk(amikbd_messages[scancode - 0x78]);
191 188
@@ -202,39 +199,41 @@ static int __init amikbd_init(void)
202 if (!request_mem_region(CIAA_PHYSADDR-1+0xb00, 0x100, "amikeyb")) 199 if (!request_mem_region(CIAA_PHYSADDR-1+0xb00, 0x100, "amikeyb"))
203 return -EBUSY; 200 return -EBUSY;
204 201
205 init_input_dev(&amikbd_dev); 202 amikbd_dev = input_dev_allocate();
206 203 if (!amikbd_dev) {
207 amikbd_dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REP); 204 printk(KERN_ERR "amikbd: not enough memory for input device\n");
208 amikbd_dev.keycode = amikbd_keycode; 205 release_mem_region(CIAA_PHYSADDR - 1 + 0xb00, 0x100);
209 amikbd_dev.keycodesize = sizeof(unsigned char); 206 return -ENOMEM;
210 amikbd_dev.keycodemax = ARRAY_SIZE(amikbd_keycode); 207 }
208
209 amikbd_dev->name = "Amiga Keyboard";
210 amikbd_dev->phys = "amikbd/input0";
211 amikbd_dev->id.bustype = BUS_AMIGA;
212 amikbd_dev->id.vendor = 0x0001;
213 amikbd_dev->id.product = 0x0001;
214 amikbd_dev->id.version = 0x0100;
215
216 amikbd_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
217 amikbd_dev->keycode = amikbd_keycode;
218 amikbd_dev->keycodesize = sizeof(unsigned char);
219 amikbd_dev->keycodemax = ARRAY_SIZE(amikbd_keycode);
211 220
212 for (i = 0; i < 0x78; i++) 221 for (i = 0; i < 0x78; i++)
213 if (amikbd_keycode[i]) 222 if (amikbd_keycode[i])
214 set_bit(amikbd_keycode[i], amikbd_dev.keybit); 223 set_bit(amikbd_keycode[i], amikbd_dev->keybit);
215 224
216 ciaa.cra &= ~0x41; /* serial data in, turn off TA */ 225 ciaa.cra &= ~0x41; /* serial data in, turn off TA */
217 request_irq(IRQ_AMIGA_CIAA_SP, amikbd_interrupt, 0, "amikbd", amikbd_interrupt); 226 request_irq(IRQ_AMIGA_CIAA_SP, amikbd_interrupt, 0, "amikbd", amikbd_interrupt);
218 227
219 amikbd_dev.name = amikbd_name; 228 input_register_device(amikbd_dev);
220 amikbd_dev.phys = amikbd_phys;
221 amikbd_dev.id.bustype = BUS_AMIGA;
222 amikbd_dev.id.vendor = 0x0001;
223 amikbd_dev.id.product = 0x0001;
224 amikbd_dev.id.version = 0x0100;
225
226 input_register_device(&amikbd_dev);
227
228 printk(KERN_INFO "input: %s\n", amikbd_name);
229
230 return 0; 229 return 0;
231} 230}
232 231
233static void __exit amikbd_exit(void) 232static void __exit amikbd_exit(void)
234{ 233{
235 input_unregister_device(&amikbd_dev);
236 free_irq(IRQ_AMIGA_CIAA_SP, amikbd_interrupt); 234 free_irq(IRQ_AMIGA_CIAA_SP, amikbd_interrupt);
237 release_mem_region(CIAA_PHYSADDR-1+0xb00, 0x100); 235 input_unregister_device(amikbd_dev);
236 release_mem_region(CIAA_PHYSADDR - 1 + 0xb00, 0x100);
238} 237}
239 238
240module_init(amikbd_init); 239module_init(amikbd_init);
diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c
index 1ad8c2ee7dbf..820c7fd9a604 100644
--- a/drivers/input/keyboard/atkbd.c
+++ b/drivers/input/keyboard/atkbd.c
@@ -185,12 +185,12 @@ static struct {
185 185
186struct atkbd { 186struct atkbd {
187 187
188 struct ps2dev ps2dev; 188 struct ps2dev ps2dev;
189 struct input_dev *dev;
189 190
190 /* Written only during init */ 191 /* Written only during init */
191 char name[64]; 192 char name[64];
192 char phys[32]; 193 char phys[32];
193 struct input_dev dev;
194 194
195 unsigned short id; 195 unsigned short id;
196 unsigned char keycode[512]; 196 unsigned char keycode[512];
@@ -290,7 +290,7 @@ static irqreturn_t atkbd_interrupt(struct serio *serio, unsigned char data,
290 if (!atkbd->enabled) 290 if (!atkbd->enabled)
291 goto out; 291 goto out;
292 292
293 input_event(&atkbd->dev, EV_MSC, MSC_RAW, code); 293 input_event(atkbd->dev, EV_MSC, MSC_RAW, code);
294 294
295 if (atkbd->translated) { 295 if (atkbd->translated) {
296 296
@@ -326,10 +326,10 @@ static irqreturn_t atkbd_interrupt(struct serio *serio, unsigned char data,
326 atkbd->release = 1; 326 atkbd->release = 1;
327 goto out; 327 goto out;
328 case ATKBD_RET_HANGUEL: 328 case ATKBD_RET_HANGUEL:
329 atkbd_report_key(&atkbd->dev, regs, KEY_HANGUEL, 3); 329 atkbd_report_key(atkbd->dev, regs, KEY_HANGUEL, 3);
330 goto out; 330 goto out;
331 case ATKBD_RET_HANJA: 331 case ATKBD_RET_HANJA:
332 atkbd_report_key(&atkbd->dev, regs, KEY_HANJA, 3); 332 atkbd_report_key(atkbd->dev, regs, KEY_HANJA, 3);
333 goto out; 333 goto out;
334 case ATKBD_RET_ERR: 334 case ATKBD_RET_ERR:
335 printk(KERN_DEBUG "atkbd.c: Keyboard on %s reports too many keys pressed.\n", serio->phys); 335 printk(KERN_DEBUG "atkbd.c: Keyboard on %s reports too many keys pressed.\n", serio->phys);
@@ -345,7 +345,7 @@ static irqreturn_t atkbd_interrupt(struct serio *serio, unsigned char data,
345 } 345 }
346 346
347 if (atkbd->keycode[code] != ATKBD_KEY_NULL) 347 if (atkbd->keycode[code] != ATKBD_KEY_NULL)
348 input_event(&atkbd->dev, EV_MSC, MSC_SCAN, code); 348 input_event(atkbd->dev, EV_MSC, MSC_SCAN, code);
349 349
350 switch (atkbd->keycode[code]) { 350 switch (atkbd->keycode[code]) {
351 case ATKBD_KEY_NULL: 351 case ATKBD_KEY_NULL:
@@ -365,7 +365,7 @@ static irqreturn_t atkbd_interrupt(struct serio *serio, unsigned char data,
365 "to make it known.\n", 365 "to make it known.\n",
366 code & 0x80 ? "e0" : "", code & 0x7f); 366 code & 0x80 ? "e0" : "", code & 0x7f);
367 } 367 }
368 input_sync(&atkbd->dev); 368 input_sync(atkbd->dev);
369 break; 369 break;
370 case ATKBD_SCR_1: 370 case ATKBD_SCR_1:
371 scroll = 1 - atkbd->release * 2; 371 scroll = 1 - atkbd->release * 2;
@@ -390,7 +390,7 @@ static irqreturn_t atkbd_interrupt(struct serio *serio, unsigned char data,
390 break; 390 break;
391 default: 391 default:
392 value = atkbd->release ? 0 : 392 value = atkbd->release ? 0 :
393 (1 + (!atkbd->softrepeat && test_bit(atkbd->keycode[code], atkbd->dev.key))); 393 (1 + (!atkbd->softrepeat && test_bit(atkbd->keycode[code], atkbd->dev->key)));
394 394
395 switch (value) { /* Workaround Toshiba laptop multiple keypress */ 395 switch (value) { /* Workaround Toshiba laptop multiple keypress */
396 case 0: 396 case 0:
@@ -398,7 +398,7 @@ static irqreturn_t atkbd_interrupt(struct serio *serio, unsigned char data,
398 break; 398 break;
399 case 1: 399 case 1:
400 atkbd->last = code; 400 atkbd->last = code;
401 atkbd->time = jiffies + msecs_to_jiffies(atkbd->dev.rep[REP_DELAY]) / 2; 401 atkbd->time = jiffies + msecs_to_jiffies(atkbd->dev->rep[REP_DELAY]) / 2;
402 break; 402 break;
403 case 2: 403 case 2:
404 if (!time_after(jiffies, atkbd->time) && atkbd->last == code) 404 if (!time_after(jiffies, atkbd->time) && atkbd->last == code)
@@ -406,16 +406,16 @@ static irqreturn_t atkbd_interrupt(struct serio *serio, unsigned char data,
406 break; 406 break;
407 } 407 }
408 408
409 atkbd_report_key(&atkbd->dev, regs, atkbd->keycode[code], value); 409 atkbd_report_key(atkbd->dev, regs, atkbd->keycode[code], value);
410 } 410 }
411 411
412 if (atkbd->scroll) { 412 if (atkbd->scroll) {
413 input_regs(&atkbd->dev, regs); 413 input_regs(atkbd->dev, regs);
414 if (click != -1) 414 if (click != -1)
415 input_report_key(&atkbd->dev, BTN_MIDDLE, click); 415 input_report_key(atkbd->dev, BTN_MIDDLE, click);
416 input_report_rel(&atkbd->dev, REL_WHEEL, scroll); 416 input_report_rel(atkbd->dev, REL_WHEEL, scroll);
417 input_report_rel(&atkbd->dev, REL_HWHEEL, hscroll); 417 input_report_rel(atkbd->dev, REL_HWHEEL, hscroll);
418 input_sync(&atkbd->dev); 418 input_sync(atkbd->dev);
419 } 419 }
420 420
421 atkbd->release = 0; 421 atkbd->release = 0;
@@ -463,7 +463,6 @@ static int atkbd_event(struct input_dev *dev, unsigned int type, unsigned int co
463 463
464 return 0; 464 return 0;
465 465
466
467 case EV_REP: 466 case EV_REP:
468 467
469 if (atkbd->softrepeat) return 0; 468 if (atkbd->softrepeat) return 0;
@@ -693,7 +692,7 @@ static void atkbd_disconnect(struct serio *serio)
693 device_remove_file(&serio->dev, &atkbd_attr_softrepeat); 692 device_remove_file(&serio->dev, &atkbd_attr_softrepeat);
694 device_remove_file(&serio->dev, &atkbd_attr_softraw); 693 device_remove_file(&serio->dev, &atkbd_attr_softraw);
695 694
696 input_unregister_device(&atkbd->dev); 695 input_unregister_device(atkbd->dev);
697 serio_close(serio); 696 serio_close(serio);
698 serio_set_drvdata(serio, NULL); 697 serio_set_drvdata(serio, NULL);
699 kfree(atkbd); 698 kfree(atkbd);
@@ -701,7 +700,7 @@ static void atkbd_disconnect(struct serio *serio)
701 700
702 701
703/* 702/*
704 * atkbd_set_device_attrs() initializes keyboard's keycode table 703 * atkbd_set_keycode_table() initializes keyboard's keycode table
705 * according to the selected scancode set 704 * according to the selected scancode set
706 */ 705 */
707 706
@@ -737,53 +736,58 @@ static void atkbd_set_keycode_table(struct atkbd *atkbd)
737 736
738static void atkbd_set_device_attrs(struct atkbd *atkbd) 737static void atkbd_set_device_attrs(struct atkbd *atkbd)
739{ 738{
739 struct input_dev *input_dev = atkbd->dev;
740 int i; 740 int i;
741 741
742 memset(&atkbd->dev, 0, sizeof(struct input_dev)); 742 if (atkbd->extra)
743 sprintf(atkbd->name, "AT Set 2 Extra keyboard");
744 else
745 sprintf(atkbd->name, "AT %s Set %d keyboard",
746 atkbd->translated ? "Translated" : "Raw", atkbd->set);
743 747
744 init_input_dev(&atkbd->dev); 748 sprintf(atkbd->phys, "%s/input0", atkbd->ps2dev.serio->phys);
745 749
746 atkbd->dev.name = atkbd->name; 750 input_dev->name = atkbd->name;
747 atkbd->dev.phys = atkbd->phys; 751 input_dev->phys = atkbd->phys;
748 atkbd->dev.id.bustype = BUS_I8042; 752 input_dev->id.bustype = BUS_I8042;
749 atkbd->dev.id.vendor = 0x0001; 753 input_dev->id.vendor = 0x0001;
750 atkbd->dev.id.product = atkbd->translated ? 1 : atkbd->set; 754 input_dev->id.product = atkbd->translated ? 1 : atkbd->set;
751 atkbd->dev.id.version = atkbd->id; 755 input_dev->id.version = atkbd->id;
752 atkbd->dev.event = atkbd_event; 756 input_dev->event = atkbd_event;
753 atkbd->dev.private = atkbd; 757 input_dev->private = atkbd;
754 atkbd->dev.dev = &atkbd->ps2dev.serio->dev; 758 input_dev->cdev.dev = &atkbd->ps2dev.serio->dev;
755 759
756 atkbd->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REP) | BIT(EV_MSC); 760 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP) | BIT(EV_MSC);
757 761
758 if (atkbd->write) { 762 if (atkbd->write) {
759 atkbd->dev.evbit[0] |= BIT(EV_LED); 763 input_dev->evbit[0] |= BIT(EV_LED);
760 atkbd->dev.ledbit[0] = BIT(LED_NUML) | BIT(LED_CAPSL) | BIT(LED_SCROLLL); 764 input_dev->ledbit[0] = BIT(LED_NUML) | BIT(LED_CAPSL) | BIT(LED_SCROLLL);
761 } 765 }
762 766
763 if (atkbd->extra) 767 if (atkbd->extra)
764 atkbd->dev.ledbit[0] |= BIT(LED_COMPOSE) | BIT(LED_SUSPEND) | 768 input_dev->ledbit[0] |= BIT(LED_COMPOSE) | BIT(LED_SUSPEND) |
765 BIT(LED_SLEEP) | BIT(LED_MUTE) | BIT(LED_MISC); 769 BIT(LED_SLEEP) | BIT(LED_MUTE) | BIT(LED_MISC);
766 770
767 if (!atkbd->softrepeat) { 771 if (!atkbd->softrepeat) {
768 atkbd->dev.rep[REP_DELAY] = 250; 772 input_dev->rep[REP_DELAY] = 250;
769 atkbd->dev.rep[REP_PERIOD] = 33; 773 input_dev->rep[REP_PERIOD] = 33;
770 } 774 }
771 775
772 atkbd->dev.mscbit[0] = atkbd->softraw ? BIT(MSC_SCAN) : BIT(MSC_RAW) | BIT(MSC_SCAN); 776 input_dev->mscbit[0] = atkbd->softraw ? BIT(MSC_SCAN) : BIT(MSC_RAW) | BIT(MSC_SCAN);
773 777
774 if (atkbd->scroll) { 778 if (atkbd->scroll) {
775 atkbd->dev.evbit[0] |= BIT(EV_REL); 779 input_dev->evbit[0] |= BIT(EV_REL);
776 atkbd->dev.relbit[0] = BIT(REL_WHEEL) | BIT(REL_HWHEEL); 780 input_dev->relbit[0] = BIT(REL_WHEEL) | BIT(REL_HWHEEL);
777 set_bit(BTN_MIDDLE, atkbd->dev.keybit); 781 set_bit(BTN_MIDDLE, input_dev->keybit);
778 } 782 }
779 783
780 atkbd->dev.keycode = atkbd->keycode; 784 input_dev->keycode = atkbd->keycode;
781 atkbd->dev.keycodesize = sizeof(unsigned char); 785 input_dev->keycodesize = sizeof(unsigned char);
782 atkbd->dev.keycodemax = ARRAY_SIZE(atkbd_set2_keycode); 786 input_dev->keycodemax = ARRAY_SIZE(atkbd_set2_keycode);
783 787
784 for (i = 0; i < 512; i++) 788 for (i = 0; i < 512; i++)
785 if (atkbd->keycode[i] && atkbd->keycode[i] < ATKBD_SPECIAL) 789 if (atkbd->keycode[i] && atkbd->keycode[i] < ATKBD_SPECIAL)
786 set_bit(atkbd->keycode[i], atkbd->dev.keybit); 790 set_bit(atkbd->keycode[i], input_dev->keybit);
787} 791}
788 792
789/* 793/*
@@ -796,13 +800,15 @@ static void atkbd_set_device_attrs(struct atkbd *atkbd)
796static int atkbd_connect(struct serio *serio, struct serio_driver *drv) 800static int atkbd_connect(struct serio *serio, struct serio_driver *drv)
797{ 801{
798 struct atkbd *atkbd; 802 struct atkbd *atkbd;
799 int err; 803 struct input_dev *dev;
800 804 int err = -ENOMEM;
801 if (!(atkbd = kmalloc(sizeof(struct atkbd), GFP_KERNEL)))
802 return - ENOMEM;
803 805
804 memset(atkbd, 0, sizeof(struct atkbd)); 806 atkbd = kzalloc(sizeof(struct atkbd), GFP_KERNEL);
807 dev = input_allocate_device();
808 if (!atkbd || !dev)
809 goto fail;
805 810
811 atkbd->dev = dev;
806 ps2_init(&atkbd->ps2dev, serio); 812 ps2_init(&atkbd->ps2dev, serio);
807 813
808 switch (serio->id.type) { 814 switch (serio->id.type) {
@@ -828,19 +834,15 @@ static int atkbd_connect(struct serio *serio, struct serio_driver *drv)
828 serio_set_drvdata(serio, atkbd); 834 serio_set_drvdata(serio, atkbd);
829 835
830 err = serio_open(serio, drv); 836 err = serio_open(serio, drv);
831 if (err) { 837 if (err)
832 serio_set_drvdata(serio, NULL); 838 goto fail;
833 kfree(atkbd);
834 return err;
835 }
836 839
837 if (atkbd->write) { 840 if (atkbd->write) {
838 841
839 if (atkbd_probe(atkbd)) { 842 if (atkbd_probe(atkbd)) {
840 serio_close(serio); 843 serio_close(serio);
841 serio_set_drvdata(serio, NULL); 844 err = -ENODEV;
842 kfree(atkbd); 845 goto fail;
843 return -ENODEV;
844 } 846 }
845 847
846 atkbd->set = atkbd_select_set(atkbd, atkbd_set, atkbd_extra); 848 atkbd->set = atkbd_select_set(atkbd, atkbd_set, atkbd_extra);
@@ -851,19 +853,9 @@ static int atkbd_connect(struct serio *serio, struct serio_driver *drv)
851 atkbd->id = 0xab00; 853 atkbd->id = 0xab00;
852 } 854 }
853 855
854 if (atkbd->extra)
855 sprintf(atkbd->name, "AT Set 2 Extra keyboard");
856 else
857 sprintf(atkbd->name, "AT %s Set %d keyboard",
858 atkbd->translated ? "Translated" : "Raw", atkbd->set);
859
860 sprintf(atkbd->phys, "%s/input0", serio->phys);
861
862 atkbd_set_keycode_table(atkbd); 856 atkbd_set_keycode_table(atkbd);
863 atkbd_set_device_attrs(atkbd); 857 atkbd_set_device_attrs(atkbd);
864 858
865 input_register_device(&atkbd->dev);
866
867 device_create_file(&serio->dev, &atkbd_attr_extra); 859 device_create_file(&serio->dev, &atkbd_attr_extra);
868 device_create_file(&serio->dev, &atkbd_attr_scroll); 860 device_create_file(&serio->dev, &atkbd_attr_scroll);
869 device_create_file(&serio->dev, &atkbd_attr_set); 861 device_create_file(&serio->dev, &atkbd_attr_set);
@@ -872,9 +864,14 @@ static int atkbd_connect(struct serio *serio, struct serio_driver *drv)
872 864
873 atkbd_enable(atkbd); 865 atkbd_enable(atkbd);
874 866
875 printk(KERN_INFO "input: %s on %s\n", atkbd->name, serio->phys); 867 input_register_device(atkbd->dev);
876 868
877 return 0; 869 return 0;
870
871 fail: serio_set_drvdata(serio, NULL);
872 input_free_device(dev);
873 kfree(atkbd);
874 return err;
878} 875}
879 876
880/* 877/*
@@ -896,9 +893,9 @@ static int atkbd_reconnect(struct serio *serio)
896 atkbd_disable(atkbd); 893 atkbd_disable(atkbd);
897 894
898 if (atkbd->write) { 895 if (atkbd->write) {
899 param[0] = (test_bit(LED_SCROLLL, atkbd->dev.led) ? 1 : 0) 896 param[0] = (test_bit(LED_SCROLLL, atkbd->dev->led) ? 1 : 0)
900 | (test_bit(LED_NUML, atkbd->dev.led) ? 2 : 0) 897 | (test_bit(LED_NUML, atkbd->dev->led) ? 2 : 0)
901 | (test_bit(LED_CAPSL, atkbd->dev.led) ? 4 : 0); 898 | (test_bit(LED_CAPSL, atkbd->dev->led) ? 4 : 0);
902 899
903 if (atkbd_probe(atkbd)) 900 if (atkbd_probe(atkbd))
904 return -1; 901 return -1;
@@ -1008,6 +1005,7 @@ static ssize_t atkbd_show_extra(struct atkbd *atkbd, char *buf)
1008 1005
1009static ssize_t atkbd_set_extra(struct atkbd *atkbd, const char *buf, size_t count) 1006static ssize_t atkbd_set_extra(struct atkbd *atkbd, const char *buf, size_t count)
1010{ 1007{
1008 struct input_dev *new_dev;
1011 unsigned long value; 1009 unsigned long value;
1012 char *rest; 1010 char *rest;
1013 1011
@@ -1019,12 +1017,19 @@ static ssize_t atkbd_set_extra(struct atkbd *atkbd, const char *buf, size_t coun
1019 return -EINVAL; 1017 return -EINVAL;
1020 1018
1021 if (atkbd->extra != value) { 1019 if (atkbd->extra != value) {
1022 /* unregister device as it's properties will change */ 1020 /*
1023 input_unregister_device(&atkbd->dev); 1021 * Since device's properties will change we need to
1022 * unregister old device. But allocate new one first
1023 * to make sure we have it.
1024 */
1025 if (!(new_dev = input_allocate_device()))
1026 return -ENOMEM;
1027 input_unregister_device(atkbd->dev);
1028 atkbd->dev = new_dev;
1024 atkbd->set = atkbd_select_set(atkbd, atkbd->set, value); 1029 atkbd->set = atkbd_select_set(atkbd, atkbd->set, value);
1025 atkbd_activate(atkbd); 1030 atkbd_activate(atkbd);
1026 atkbd_set_device_attrs(atkbd); 1031 atkbd_set_device_attrs(atkbd);
1027 input_register_device(&atkbd->dev); 1032 input_register_device(atkbd->dev);
1028 } 1033 }
1029 return count; 1034 return count;
1030} 1035}
@@ -1036,6 +1041,7 @@ static ssize_t atkbd_show_scroll(struct atkbd *atkbd, char *buf)
1036 1041
1037static ssize_t atkbd_set_scroll(struct atkbd *atkbd, const char *buf, size_t count) 1042static ssize_t atkbd_set_scroll(struct atkbd *atkbd, const char *buf, size_t count)
1038{ 1043{
1044 struct input_dev *new_dev;
1039 unsigned long value; 1045 unsigned long value;
1040 char *rest; 1046 char *rest;
1041 1047
@@ -1044,12 +1050,14 @@ static ssize_t atkbd_set_scroll(struct atkbd *atkbd, const char *buf, size_t cou
1044 return -EINVAL; 1050 return -EINVAL;
1045 1051
1046 if (atkbd->scroll != value) { 1052 if (atkbd->scroll != value) {
1047 /* unregister device as it's properties will change */ 1053 if (!(new_dev = input_allocate_device()))
1048 input_unregister_device(&atkbd->dev); 1054 return -ENOMEM;
1055 input_unregister_device(atkbd->dev);
1056 atkbd->dev = new_dev;
1049 atkbd->scroll = value; 1057 atkbd->scroll = value;
1050 atkbd_set_keycode_table(atkbd); 1058 atkbd_set_keycode_table(atkbd);
1051 atkbd_set_device_attrs(atkbd); 1059 atkbd_set_device_attrs(atkbd);
1052 input_register_device(&atkbd->dev); 1060 input_register_device(atkbd->dev);
1053 } 1061 }
1054 return count; 1062 return count;
1055} 1063}
@@ -1061,6 +1069,7 @@ static ssize_t atkbd_show_set(struct atkbd *atkbd, char *buf)
1061 1069
1062static ssize_t atkbd_set_set(struct atkbd *atkbd, const char *buf, size_t count) 1070static ssize_t atkbd_set_set(struct atkbd *atkbd, const char *buf, size_t count)
1063{ 1071{
1072 struct input_dev *new_dev;
1064 unsigned long value; 1073 unsigned long value;
1065 char *rest; 1074 char *rest;
1066 1075
@@ -1072,13 +1081,15 @@ static ssize_t atkbd_set_set(struct atkbd *atkbd, const char *buf, size_t count)
1072 return -EINVAL; 1081 return -EINVAL;
1073 1082
1074 if (atkbd->set != value) { 1083 if (atkbd->set != value) {
1075 /* unregister device as it's properties will change */ 1084 if (!(new_dev = input_allocate_device()))
1076 input_unregister_device(&atkbd->dev); 1085 return -ENOMEM;
1086 input_unregister_device(atkbd->dev);
1087 atkbd->dev = new_dev;
1077 atkbd->set = atkbd_select_set(atkbd, value, atkbd->extra); 1088 atkbd->set = atkbd_select_set(atkbd, value, atkbd->extra);
1078 atkbd_activate(atkbd); 1089 atkbd_activate(atkbd);
1079 atkbd_set_keycode_table(atkbd); 1090 atkbd_set_keycode_table(atkbd);
1080 atkbd_set_device_attrs(atkbd); 1091 atkbd_set_device_attrs(atkbd);
1081 input_register_device(&atkbd->dev); 1092 input_register_device(atkbd->dev);
1082 } 1093 }
1083 return count; 1094 return count;
1084} 1095}
@@ -1090,6 +1101,7 @@ static ssize_t atkbd_show_softrepeat(struct atkbd *atkbd, char *buf)
1090 1101
1091static ssize_t atkbd_set_softrepeat(struct atkbd *atkbd, const char *buf, size_t count) 1102static ssize_t atkbd_set_softrepeat(struct atkbd *atkbd, const char *buf, size_t count)
1092{ 1103{
1104 struct input_dev *new_dev;
1093 unsigned long value; 1105 unsigned long value;
1094 char *rest; 1106 char *rest;
1095 1107
@@ -1101,15 +1113,16 @@ static ssize_t atkbd_set_softrepeat(struct atkbd *atkbd, const char *buf, size_t
1101 return -EINVAL; 1113 return -EINVAL;
1102 1114
1103 if (atkbd->softrepeat != value) { 1115 if (atkbd->softrepeat != value) {
1104 /* unregister device as it's properties will change */ 1116 if (!(new_dev = input_allocate_device()))
1105 input_unregister_device(&atkbd->dev); 1117 return -ENOMEM;
1118 input_unregister_device(atkbd->dev);
1119 atkbd->dev = new_dev;
1106 atkbd->softrepeat = value; 1120 atkbd->softrepeat = value;
1107 if (atkbd->softrepeat) 1121 if (atkbd->softrepeat)
1108 atkbd->softraw = 1; 1122 atkbd->softraw = 1;
1109 atkbd_set_device_attrs(atkbd); 1123 atkbd_set_device_attrs(atkbd);
1110 input_register_device(&atkbd->dev); 1124 input_register_device(atkbd->dev);
1111 } 1125 }
1112
1113 return count; 1126 return count;
1114} 1127}
1115 1128
@@ -1121,6 +1134,7 @@ static ssize_t atkbd_show_softraw(struct atkbd *atkbd, char *buf)
1121 1134
1122static ssize_t atkbd_set_softraw(struct atkbd *atkbd, const char *buf, size_t count) 1135static ssize_t atkbd_set_softraw(struct atkbd *atkbd, const char *buf, size_t count)
1123{ 1136{
1137 struct input_dev *new_dev;
1124 unsigned long value; 1138 unsigned long value;
1125 char *rest; 1139 char *rest;
1126 1140
@@ -1129,11 +1143,13 @@ static ssize_t atkbd_set_softraw(struct atkbd *atkbd, const char *buf, size_t co
1129 return -EINVAL; 1143 return -EINVAL;
1130 1144
1131 if (atkbd->softraw != value) { 1145 if (atkbd->softraw != value) {
1132 /* unregister device as it's properties will change */ 1146 if (!(new_dev = input_allocate_device()))
1133 input_unregister_device(&atkbd->dev); 1147 return -ENOMEM;
1148 input_unregister_device(atkbd->dev);
1149 atkbd->dev = new_dev;
1134 atkbd->softraw = value; 1150 atkbd->softraw = value;
1135 atkbd_set_device_attrs(atkbd); 1151 atkbd_set_device_attrs(atkbd);
1136 input_register_device(&atkbd->dev); 1152 input_register_device(atkbd->dev);
1137 } 1153 }
1138 return count; 1154 return count;
1139} 1155}
diff --git a/drivers/input/keyboard/corgikbd.c b/drivers/input/keyboard/corgikbd.c
index cd4b6e795013..3210d298b3bc 100644
--- a/drivers/input/keyboard/corgikbd.c
+++ b/drivers/input/keyboard/corgikbd.c
@@ -70,8 +70,7 @@ static unsigned char corgikbd_keycode[NR_SCANCODES] = {
70 70
71struct corgikbd { 71struct corgikbd {
72 unsigned char keycode[ARRAY_SIZE(corgikbd_keycode)]; 72 unsigned char keycode[ARRAY_SIZE(corgikbd_keycode)];
73 struct input_dev input; 73 struct input_dev *input;
74 char phys[32];
75 74
76 spinlock_t lock; 75 spinlock_t lock;
77 struct timer_list timer; 76 struct timer_list timer;
@@ -147,7 +146,7 @@ static void corgikbd_scankeyboard(struct corgikbd *corgikbd_data, struct pt_regs
147 spin_lock_irqsave(&corgikbd_data->lock, flags); 146 spin_lock_irqsave(&corgikbd_data->lock, flags);
148 147
149 if (regs) 148 if (regs)
150 input_regs(&corgikbd_data->input, regs); 149 input_regs(corgikbd_data->input, regs);
151 150
152 num_pressed = 0; 151 num_pressed = 0;
153 for (col = 0; col < KB_COLS; col++) { 152 for (col = 0; col < KB_COLS; col++) {
@@ -169,14 +168,14 @@ static void corgikbd_scankeyboard(struct corgikbd *corgikbd_data, struct pt_regs
169 scancode = SCANCODE(row, col); 168 scancode = SCANCODE(row, col);
170 pressed = rowd & KB_ROWMASK(row); 169 pressed = rowd & KB_ROWMASK(row);
171 170
172 input_report_key(&corgikbd_data->input, corgikbd_data->keycode[scancode], pressed); 171 input_report_key(corgikbd_data->input, corgikbd_data->keycode[scancode], pressed);
173 172
174 if (pressed) 173 if (pressed)
175 num_pressed++; 174 num_pressed++;
176 175
177 if (pressed && (corgikbd_data->keycode[scancode] == CORGI_KEY_OFF) 176 if (pressed && (corgikbd_data->keycode[scancode] == CORGI_KEY_OFF)
178 && time_after(jiffies, corgikbd_data->suspend_jiffies + HZ)) { 177 && time_after(jiffies, corgikbd_data->suspend_jiffies + HZ)) {
179 input_event(&corgikbd_data->input, EV_PWR, CORGI_KEY_OFF, 1); 178 input_event(corgikbd_data->input, EV_PWR, CORGI_KEY_OFF, 1);
180 corgikbd_data->suspend_jiffies=jiffies; 179 corgikbd_data->suspend_jiffies=jiffies;
181 } 180 }
182 } 181 }
@@ -185,7 +184,7 @@ static void corgikbd_scankeyboard(struct corgikbd *corgikbd_data, struct pt_regs
185 184
186 corgikbd_activate_all(); 185 corgikbd_activate_all();
187 186
188 input_sync(&corgikbd_data->input); 187 input_sync(corgikbd_data->input);
189 188
190 /* if any keys are pressed, enable the timer */ 189 /* if any keys are pressed, enable the timer */
191 if (num_pressed) 190 if (num_pressed)
@@ -249,9 +248,9 @@ static void corgikbd_hinge_timer(unsigned long data)
249 if (hinge_count >= HINGE_STABLE_COUNT) { 248 if (hinge_count >= HINGE_STABLE_COUNT) {
250 spin_lock_irqsave(&corgikbd_data->lock, flags); 249 spin_lock_irqsave(&corgikbd_data->lock, flags);
251 250
252 input_report_switch(&corgikbd_data->input, SW_0, ((sharpsl_hinge_state & CORGI_SCP_SWA) != 0)); 251 input_report_switch(corgikbd_data->input, SW_0, ((sharpsl_hinge_state & CORGI_SCP_SWA) != 0));
253 input_report_switch(&corgikbd_data->input, SW_1, ((sharpsl_hinge_state & CORGI_SCP_SWB) != 0)); 252 input_report_switch(corgikbd_data->input, SW_1, ((sharpsl_hinge_state & CORGI_SCP_SWB) != 0));
254 input_sync(&corgikbd_data->input); 253 input_sync(corgikbd_data->input);
255 254
256 spin_unlock_irqrestore(&corgikbd_data->lock, flags); 255 spin_unlock_irqrestore(&corgikbd_data->lock, flags);
257 } 256 }
@@ -260,24 +259,22 @@ static void corgikbd_hinge_timer(unsigned long data)
260} 259}
261 260
262#ifdef CONFIG_PM 261#ifdef CONFIG_PM
263static int corgikbd_suspend(struct device *dev, pm_message_t state, uint32_t level) 262static int corgikbd_suspend(struct device *dev, pm_message_t state)
264{ 263{
265 if (level == SUSPEND_POWER_DOWN) { 264 struct corgikbd *corgikbd = dev_get_drvdata(dev);
266 struct corgikbd *corgikbd = dev_get_drvdata(dev); 265 corgikbd->suspended = 1;
267 corgikbd->suspended = 1; 266
268 }
269 return 0; 267 return 0;
270} 268}
271 269
272static int corgikbd_resume(struct device *dev, uint32_t level) 270static int corgikbd_resume(struct device *dev)
273{ 271{
274 if (level == RESUME_POWER_ON) { 272 struct corgikbd *corgikbd = dev_get_drvdata(dev);
275 struct corgikbd *corgikbd = dev_get_drvdata(dev); 273
274 /* Upon resume, ignore the suspend key for a short while */
275 corgikbd->suspend_jiffies=jiffies;
276 corgikbd->suspended = 0;
276 277
277 /* Upon resume, ignore the suspend key for a short while */
278 corgikbd->suspend_jiffies=jiffies;
279 corgikbd->suspended = 0;
280 }
281 return 0; 278 return 0;
282} 279}
283#else 280#else
@@ -287,16 +284,21 @@ static int corgikbd_resume(struct device *dev, uint32_t level)
287 284
288static int __init corgikbd_probe(struct device *dev) 285static int __init corgikbd_probe(struct device *dev)
289{ 286{
290 int i;
291 struct corgikbd *corgikbd; 287 struct corgikbd *corgikbd;
288 struct input_dev *input_dev;
289 int i;
292 290
293 corgikbd = kzalloc(sizeof(struct corgikbd), GFP_KERNEL); 291 corgikbd = kzalloc(sizeof(struct corgikbd), GFP_KERNEL);
294 if (!corgikbd) 292 input_dev = input_allocate_device();
293 if (!corgikbd || !input_dev) {
294 kfree(corgikbd);
295 input_free_device(input_dev);
295 return -ENOMEM; 296 return -ENOMEM;
297 }
296 298
297 dev_set_drvdata(dev,corgikbd); 299 dev_set_drvdata(dev, corgikbd);
298 strcpy(corgikbd->phys, "corgikbd/input0");
299 300
301 corgikbd->input = input_dev;
300 spin_lock_init(&corgikbd->lock); 302 spin_lock_init(&corgikbd->lock);
301 303
302 /* Init Keyboard rescan timer */ 304 /* Init Keyboard rescan timer */
@@ -311,28 +313,30 @@ static int __init corgikbd_probe(struct device *dev)
311 313
312 corgikbd->suspend_jiffies=jiffies; 314 corgikbd->suspend_jiffies=jiffies;
313 315
314 init_input_dev(&corgikbd->input);
315 corgikbd->input.private = corgikbd;
316 corgikbd->input.name = "Corgi Keyboard";
317 corgikbd->input.dev = dev;
318 corgikbd->input.phys = corgikbd->phys;
319 corgikbd->input.id.bustype = BUS_HOST;
320 corgikbd->input.id.vendor = 0x0001;
321 corgikbd->input.id.product = 0x0001;
322 corgikbd->input.id.version = 0x0100;
323 corgikbd->input.evbit[0] = BIT(EV_KEY) | BIT(EV_REP) | BIT(EV_PWR) | BIT(EV_SW);
324 corgikbd->input.keycode = corgikbd->keycode;
325 corgikbd->input.keycodesize = sizeof(unsigned char);
326 corgikbd->input.keycodemax = ARRAY_SIZE(corgikbd_keycode);
327
328 memcpy(corgikbd->keycode, corgikbd_keycode, sizeof(corgikbd->keycode)); 316 memcpy(corgikbd->keycode, corgikbd_keycode, sizeof(corgikbd->keycode));
317
318 input_dev->name = "Corgi Keyboard";
319 input_dev->phys = "corgikbd/input0";
320 input_dev->id.bustype = BUS_HOST;
321 input_dev->id.vendor = 0x0001;
322 input_dev->id.product = 0x0001;
323 input_dev->id.version = 0x0100;
324 input_dev->cdev.dev = dev;
325 input_dev->private = corgikbd;
326
327 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP) | BIT(EV_PWR) | BIT(EV_SW);
328 input_dev->keycode = corgikbd->keycode;
329 input_dev->keycodesize = sizeof(unsigned char);
330 input_dev->keycodemax = ARRAY_SIZE(corgikbd_keycode);
331
329 for (i = 0; i < ARRAY_SIZE(corgikbd_keycode); i++) 332 for (i = 0; i < ARRAY_SIZE(corgikbd_keycode); i++)
330 set_bit(corgikbd->keycode[i], corgikbd->input.keybit); 333 set_bit(corgikbd->keycode[i], input_dev->keybit);
331 clear_bit(0, corgikbd->input.keybit); 334 clear_bit(0, input_dev->keybit);
332 set_bit(SW_0, corgikbd->input.swbit); 335 set_bit(SW_0, input_dev->swbit);
333 set_bit(SW_1, corgikbd->input.swbit); 336 set_bit(SW_1, input_dev->swbit);
337
338 input_register_device(corgikbd->input);
334 339
335 input_register_device(&corgikbd->input);
336 mod_timer(&corgikbd->htimer, jiffies + HINGE_SCAN_INTERVAL); 340 mod_timer(&corgikbd->htimer, jiffies + HINGE_SCAN_INTERVAL);
337 341
338 /* Setup sense interrupts - RisingEdge Detect, sense lines as inputs */ 342 /* Setup sense interrupts - RisingEdge Detect, sense lines as inputs */
@@ -349,8 +353,6 @@ static int __init corgikbd_probe(struct device *dev)
349 for (i = 0; i < CORGI_KEY_STROBE_NUM; i++) 353 for (i = 0; i < CORGI_KEY_STROBE_NUM; i++)
350 pxa_gpio_mode(CORGI_GPIO_KEY_STROBE(i) | GPIO_OUT | GPIO_DFLT_HIGH); 354 pxa_gpio_mode(CORGI_GPIO_KEY_STROBE(i) | GPIO_OUT | GPIO_DFLT_HIGH);
351 355
352 printk(KERN_INFO "input: Corgi Keyboard Registered\n");
353
354 return 0; 356 return 0;
355} 357}
356 358
@@ -365,7 +367,7 @@ static int corgikbd_remove(struct device *dev)
365 del_timer_sync(&corgikbd->htimer); 367 del_timer_sync(&corgikbd->htimer);
366 del_timer_sync(&corgikbd->timer); 368 del_timer_sync(&corgikbd->timer);
367 369
368 input_unregister_device(&corgikbd->input); 370 input_unregister_device(corgikbd->input);
369 371
370 kfree(corgikbd); 372 kfree(corgikbd);
371 373
diff --git a/drivers/input/keyboard/lkkbd.c b/drivers/input/keyboard/lkkbd.c
index 098963c7cdd6..7f06780a437f 100644
--- a/drivers/input/keyboard/lkkbd.c
+++ b/drivers/input/keyboard/lkkbd.c
@@ -102,7 +102,7 @@ static int ctrlclick_volume = 100; /* % */
102module_param (ctrlclick_volume, int, 0); 102module_param (ctrlclick_volume, int, 0);
103MODULE_PARM_DESC (ctrlclick_volume, "Ctrlclick volume (in %), default is 100%"); 103MODULE_PARM_DESC (ctrlclick_volume, "Ctrlclick volume (in %), default is 100%");
104 104
105static int lk201_compose_is_alt = 0; 105static int lk201_compose_is_alt;
106module_param (lk201_compose_is_alt, int, 0); 106module_param (lk201_compose_is_alt, int, 0);
107MODULE_PARM_DESC (lk201_compose_is_alt, "If set non-zero, LK201' Compose key " 107MODULE_PARM_DESC (lk201_compose_is_alt, "If set non-zero, LK201' Compose key "
108 "will act as an Alt key"); 108 "will act as an Alt key");
@@ -274,7 +274,7 @@ static lk_keycode_t lkkbd_keycode[LK_NUM_KEYCODES] = {
274}; 274};
275 275
276#define CHECK_LED(LED, BITS) do { \ 276#define CHECK_LED(LED, BITS) do { \
277 if (test_bit (LED, lk->dev.led)) \ 277 if (test_bit (LED, lk->dev->led)) \
278 leds_on |= BITS; \ 278 leds_on |= BITS; \
279 else \ 279 else \
280 leds_off |= BITS; \ 280 leds_off |= BITS; \
@@ -287,7 +287,7 @@ struct lkkbd {
287 lk_keycode_t keycode[LK_NUM_KEYCODES]; 287 lk_keycode_t keycode[LK_NUM_KEYCODES];
288 int ignore_bytes; 288 int ignore_bytes;
289 unsigned char id[LK_NUM_IGNORE_BYTES]; 289 unsigned char id[LK_NUM_IGNORE_BYTES];
290 struct input_dev dev; 290 struct input_dev *dev;
291 struct serio *serio; 291 struct serio *serio;
292 struct work_struct tq; 292 struct work_struct tq;
293 char name[64]; 293 char name[64];
@@ -423,8 +423,7 @@ lkkbd_interrupt (struct serio *serio, unsigned char data, unsigned int flags,
423 DBG (KERN_INFO "Got byte 0x%02x\n", data); 423 DBG (KERN_INFO "Got byte 0x%02x\n", data);
424 424
425 if (lk->ignore_bytes > 0) { 425 if (lk->ignore_bytes > 0) {
426 DBG (KERN_INFO "Ignoring a byte on %s\n", 426 DBG (KERN_INFO "Ignoring a byte on %s\n", lk->name);
427 lk->name);
428 lk->id[LK_NUM_IGNORE_BYTES - lk->ignore_bytes--] = data; 427 lk->id[LK_NUM_IGNORE_BYTES - lk->ignore_bytes--] = data;
429 428
430 if (lk->ignore_bytes == 0) 429 if (lk->ignore_bytes == 0)
@@ -435,14 +434,14 @@ lkkbd_interrupt (struct serio *serio, unsigned char data, unsigned int flags,
435 434
436 switch (data) { 435 switch (data) {
437 case LK_ALL_KEYS_UP: 436 case LK_ALL_KEYS_UP:
438 input_regs (&lk->dev, regs); 437 input_regs (lk->dev, regs);
439 for (i = 0; i < ARRAY_SIZE (lkkbd_keycode); i++) 438 for (i = 0; i < ARRAY_SIZE (lkkbd_keycode); i++)
440 if (lk->keycode[i] != KEY_RESERVED) 439 if (lk->keycode[i] != KEY_RESERVED)
441 input_report_key (&lk->dev, lk->keycode[i], 0); 440 input_report_key (lk->dev, lk->keycode[i], 0);
442 input_sync (&lk->dev); 441 input_sync (lk->dev);
443 break; 442 break;
444 case LK_METRONOME: 443 case LK_METRONOME:
445 DBG (KERN_INFO "Got LK_METRONOME and don't " 444 DBG (KERN_INFO "Got %#d and don't "
446 "know how to handle...\n"); 445 "know how to handle...\n");
447 break; 446 break;
448 case LK_OUTPUT_ERROR: 447 case LK_OUTPUT_ERROR:
@@ -482,12 +481,12 @@ lkkbd_interrupt (struct serio *serio, unsigned char data, unsigned int flags,
482 481
483 default: 482 default:
484 if (lk->keycode[data] != KEY_RESERVED) { 483 if (lk->keycode[data] != KEY_RESERVED) {
485 input_regs (&lk->dev, regs); 484 input_regs (lk->dev, regs);
486 if (!test_bit (lk->keycode[data], lk->dev.key)) 485 if (!test_bit (lk->keycode[data], lk->dev->key))
487 input_report_key (&lk->dev, lk->keycode[data], 1); 486 input_report_key (lk->dev, lk->keycode[data], 1);
488 else 487 else
489 input_report_key (&lk->dev, lk->keycode[data], 0); 488 input_report_key (lk->dev, lk->keycode[data], 0);
490 input_sync (&lk->dev); 489 input_sync (lk->dev);
491 } else 490 } else
492 printk (KERN_WARNING "%s: Unknown key with " 491 printk (KERN_WARNING "%s: Unknown key with "
493 "scancode 0x%02x on %s.\n", 492 "scancode 0x%02x on %s.\n",
@@ -605,7 +604,7 @@ lkkbd_reinit (void *data)
605 lk->serio->write (lk->serio, volume_to_hw (lk->bell_volume)); 604 lk->serio->write (lk->serio, volume_to_hw (lk->bell_volume));
606 605
607 /* Enable/disable keyclick (and possibly set volume) */ 606 /* Enable/disable keyclick (and possibly set volume) */
608 if (test_bit (SND_CLICK, lk->dev.snd)) { 607 if (test_bit (SND_CLICK, lk->dev->snd)) {
609 lk->serio->write (lk->serio, LK_CMD_ENABLE_KEYCLICK); 608 lk->serio->write (lk->serio, LK_CMD_ENABLE_KEYCLICK);
610 lk->serio->write (lk->serio, volume_to_hw (lk->keyclick_volume)); 609 lk->serio->write (lk->serio, volume_to_hw (lk->keyclick_volume));
611 lk->serio->write (lk->serio, LK_CMD_ENABLE_CTRCLICK); 610 lk->serio->write (lk->serio, LK_CMD_ENABLE_CTRCLICK);
@@ -616,7 +615,7 @@ lkkbd_reinit (void *data)
616 } 615 }
617 616
618 /* Sound the bell if needed */ 617 /* Sound the bell if needed */
619 if (test_bit (SND_BELL, lk->dev.snd)) 618 if (test_bit (SND_BELL, lk->dev->snd))
620 lk->serio->write (lk->serio, LK_CMD_SOUND_BELL); 619 lk->serio->write (lk->serio, LK_CMD_SOUND_BELL);
621} 620}
622 621
@@ -627,71 +626,70 @@ static int
627lkkbd_connect (struct serio *serio, struct serio_driver *drv) 626lkkbd_connect (struct serio *serio, struct serio_driver *drv)
628{ 627{
629 struct lkkbd *lk; 628 struct lkkbd *lk;
629 struct input_dev *input_dev;
630 int i; 630 int i;
631 int err; 631 int err;
632 632
633 if (!(lk = kmalloc (sizeof (struct lkkbd), GFP_KERNEL))) 633 lk = kzalloc (sizeof (struct lkkbd), GFP_KERNEL);
634 return -ENOMEM; 634 input_dev = input_allocate_device ();
635 635 if (!lk || !input_dev) {
636 memset (lk, 0, sizeof (struct lkkbd)); 636 err = -ENOMEM;
637 637 goto fail;
638 init_input_dev (&lk->dev); 638 }
639 set_bit (EV_KEY, lk->dev.evbit);
640 set_bit (EV_LED, lk->dev.evbit);
641 set_bit (EV_SND, lk->dev.evbit);
642 set_bit (EV_REP, lk->dev.evbit);
643 set_bit (LED_CAPSL, lk->dev.ledbit);
644 set_bit (LED_SLEEP, lk->dev.ledbit);
645 set_bit (LED_COMPOSE, lk->dev.ledbit);
646 set_bit (LED_SCROLLL, lk->dev.ledbit);
647 set_bit (SND_BELL, lk->dev.sndbit);
648 set_bit (SND_CLICK, lk->dev.sndbit);
649 639
650 lk->serio = serio; 640 lk->serio = serio;
651 641 lk->dev = input_dev;
652 INIT_WORK (&lk->tq, lkkbd_reinit, lk); 642 INIT_WORK (&lk->tq, lkkbd_reinit, lk);
653
654 lk->bell_volume = bell_volume; 643 lk->bell_volume = bell_volume;
655 lk->keyclick_volume = keyclick_volume; 644 lk->keyclick_volume = keyclick_volume;
656 lk->ctrlclick_volume = ctrlclick_volume; 645 lk->ctrlclick_volume = ctrlclick_volume;
646 memcpy (lk->keycode, lkkbd_keycode, sizeof (lk_keycode_t) * LK_NUM_KEYCODES);
657 647
658 lk->dev.keycode = lk->keycode; 648 strlcpy (lk->name, "DEC LK keyboard", sizeof(lk->name));
659 lk->dev.keycodesize = sizeof (lk_keycode_t); 649 snprintf (lk->phys, sizeof(lk->phys), "%s/input0", serio->phys);
660 lk->dev.keycodemax = LK_NUM_KEYCODES; 650
661 651 input_dev->name = lk->name;
662 lk->dev.event = lkkbd_event; 652 input_dev->phys = lk->phys;
663 lk->dev.private = lk; 653 input_dev->id.bustype = BUS_RS232;
654 input_dev->id.vendor = SERIO_LKKBD;
655 input_dev->id.product = 0;
656 input_dev->id.version = 0x0100;
657 input_dev->cdev.dev = &serio->dev;
658 input_dev->event = lkkbd_event;
659 input_dev->private = lk;
660
661 set_bit (EV_KEY, input_dev->evbit);
662 set_bit (EV_LED, input_dev->evbit);
663 set_bit (EV_SND, input_dev->evbit);
664 set_bit (EV_REP, input_dev->evbit);
665 set_bit (LED_CAPSL, input_dev->ledbit);
666 set_bit (LED_SLEEP, input_dev->ledbit);
667 set_bit (LED_COMPOSE, input_dev->ledbit);
668 set_bit (LED_SCROLLL, input_dev->ledbit);
669 set_bit (SND_BELL, input_dev->sndbit);
670 set_bit (SND_CLICK, input_dev->sndbit);
671
672 input_dev->keycode = lk->keycode;
673 input_dev->keycodesize = sizeof (lk_keycode_t);
674 input_dev->keycodemax = LK_NUM_KEYCODES;
675 for (i = 0; i < LK_NUM_KEYCODES; i++)
676 set_bit (lk->keycode[i], input_dev->keybit);
664 677
665 serio_set_drvdata (serio, lk); 678 serio_set_drvdata (serio, lk);
666 679
667 err = serio_open (serio, drv); 680 err = serio_open (serio, drv);
668 if (err) { 681 if (err)
669 serio_set_drvdata (serio, NULL); 682 goto fail;
670 kfree (lk);
671 return err;
672 }
673 683
674 sprintf (lk->name, "DEC LK keyboard"); 684 input_register_device (lk->dev);
675 sprintf (lk->phys, "%s/input0", serio->phys);
676
677 memcpy (lk->keycode, lkkbd_keycode, sizeof (lk_keycode_t) * LK_NUM_KEYCODES);
678 for (i = 0; i < LK_NUM_KEYCODES; i++)
679 set_bit (lk->keycode[i], lk->dev.keybit);
680
681 lk->dev.name = lk->name;
682 lk->dev.phys = lk->phys;
683 lk->dev.id.bustype = BUS_RS232;
684 lk->dev.id.vendor = SERIO_LKKBD;
685 lk->dev.id.product = 0;
686 lk->dev.id.version = 0x0100;
687 lk->dev.dev = &serio->dev;
688
689 input_register_device (&lk->dev);
690
691 printk (KERN_INFO "input: %s on %s, initiating reset\n", lk->name, serio->phys);
692 lk->serio->write (lk->serio, LK_CMD_POWERCYCLE_RESET); 685 lk->serio->write (lk->serio, LK_CMD_POWERCYCLE_RESET);
693 686
694 return 0; 687 return 0;
688
689 fail: serio_set_drvdata (serio, NULL);
690 input_free_device (input_dev);
691 kfree (lk);
692 return err;
695} 693}
696 694
697/* 695/*
@@ -702,9 +700,11 @@ lkkbd_disconnect (struct serio *serio)
702{ 700{
703 struct lkkbd *lk = serio_get_drvdata (serio); 701 struct lkkbd *lk = serio_get_drvdata (serio);
704 702
705 input_unregister_device (&lk->dev); 703 input_get_device (lk->dev);
704 input_unregister_device (lk->dev);
706 serio_close (serio); 705 serio_close (serio);
707 serio_set_drvdata (serio, NULL); 706 serio_set_drvdata (serio, NULL);
707 input_put_device (lk->dev);
708 kfree (lk); 708 kfree (lk);
709} 709}
710 710
diff --git a/drivers/input/keyboard/maple_keyb.c b/drivers/input/keyboard/maple_keyb.c
index eecbde294f1f..cc6aaf9e85be 100644
--- a/drivers/input/keyboard/maple_keyb.c
+++ b/drivers/input/keyboard/maple_keyb.c
@@ -37,7 +37,7 @@ static unsigned char dc_kbd_keycode[256] = {
37 37
38 38
39struct dc_kbd { 39struct dc_kbd {
40 struct input_dev dev; 40 struct input_dev *dev;
41 unsigned char new[8]; 41 unsigned char new[8];
42 unsigned char old[8]; 42 unsigned char old[8];
43}; 43};
@@ -46,30 +46,24 @@ struct dc_kbd {
46static void dc_scan_kbd(struct dc_kbd *kbd) 46static void dc_scan_kbd(struct dc_kbd *kbd)
47{ 47{
48 int i; 48 int i;
49 struct input_dev *dev = &kbd->dev; 49 struct input_dev *dev = kbd->dev;
50 50
51 for(i=0; i<8; i++) 51 for (i = 0; i < 8; i++)
52 input_report_key(dev, 52 input_report_key(dev, dc_kbd_keycode[i + 224], (kbd->new[0] >> i) & 1);
53 dc_kbd_keycode[i+224],
54 (kbd->new[0]>>i)&1);
55 53
56 for(i=2; i<8; i++) { 54 for (i = 2; i < 8; i++) {
57 55
58 if(kbd->old[i]>3&&memscan(kbd->new+2, kbd->old[i], 6)==NULL) { 56 if (kbd->old[i] > 3 && memscan(kbd->new + 2, kbd->old[i], 6) == NULL) {
59 if(dc_kbd_keycode[kbd->old[i]]) 57 if (dc_kbd_keycode[kbd->old[i]])
60 input_report_key(dev, 58 input_report_key(dev, dc_kbd_keycode[kbd->old[i]], 0);
61 dc_kbd_keycode[kbd->old[i]],
62 0);
63 else 59 else
64 printk("Unknown key (scancode %#x) released.", 60 printk("Unknown key (scancode %#x) released.",
65 kbd->old[i]); 61 kbd->old[i]);
66 } 62 }
67 63
68 if(kbd->new[i]>3&&memscan(kbd->old+2, kbd->new[i], 6)!=NULL) { 64 if (kbd->new[i] > 3 && memscan(kbd->old + 2, kbd->new[i], 6) != NULL) {
69 if(dc_kbd_keycode[kbd->new[i]]) 65 if(dc_kbd_keycode[kbd->new[i]])
70 input_report_key(dev, 66 input_report_key(dev, dc_kbd_keycode[kbd->new[i]], 1);
71 dc_kbd_keycode[kbd->new[i]],
72 1);
73 else 67 else
74 printk("Unknown key (scancode %#x) pressed.", 68 printk("Unknown key (scancode %#x) pressed.",
75 kbd->new[i]); 69 kbd->new[i]);
@@ -89,43 +83,39 @@ static void dc_kbd_callback(struct mapleq *mq)
89 unsigned long *buf = mq->recvbuf; 83 unsigned long *buf = mq->recvbuf;
90 84
91 if (buf[1] == mapledev->function) { 85 if (buf[1] == mapledev->function) {
92 memcpy(kbd->new, buf+2, 8); 86 memcpy(kbd->new, buf + 2, 8);
93 dc_scan_kbd(kbd); 87 dc_scan_kbd(kbd);
94 } 88 }
95} 89}
96 90
97static int dc_kbd_connect(struct maple_device *dev) 91static int dc_kbd_connect(struct maple_device *dev)
98{ 92{
99 int i;
100 unsigned long data = be32_to_cpu(dev->devinfo.function_data[0]);
101 struct dc_kbd *kbd; 93 struct dc_kbd *kbd;
94 struct input_dev *input_dev;
95 unsigned long data = be32_to_cpu(dev->devinfo.function_data[0]);
96 int i;
102 97
103 if (!(kbd = kmalloc(sizeof(struct dc_kbd), GFP_KERNEL))) 98 dev->private_data = kbd = kzalloc(sizeof(struct dc_kbd), GFP_KERNEL);
104 return -1; 99 input_dev = input_allocate_device();
105 memset(kbd, 0, sizeof(struct dc_kbd)); 100 if (!kbd || !input_dev) {
106 101 kfree(kbd);
107 dev->private_data = kbd; 102 input_free_device(input_dev);
108 103 return -ENOMEM;
109 kbd->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REP); 104 }
110
111 init_input_dev(&kbd->dev);
112
113 for (i=0; i<255; i++)
114 set_bit(dc_kbd_keycode[i], kbd->dev.keybit);
115
116 clear_bit(0, kbd->dev.keybit);
117 105
118 kbd->dev.private = kbd; 106 kbd->dev = input_dev;
119 107
120 kbd->dev.name = dev->product_name; 108 input_dev->name = dev->product_name;
121 kbd->dev.id.bustype = BUS_MAPLE; 109 input_dev->id.bustype = BUS_MAPLE;
110 input_dev->private = kbd;
111 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
112 for (i = 0; i < 255; i++)
113 set_bit(dc_kbd_keycode[i], input_dev->keybit);
114 clear_bit(0, input_dev->keybit);
122 115
123 input_register_device(&kbd->dev); 116 input_register_device(kbd->dev);
124 117
125 maple_getcond_callback(dev, dc_kbd_callback, 1, MAPLE_FUNC_KEYBOARD); 118 maple_getcond_callback(dev, dc_kbd_callback, 1, MAPLE_FUNC_KEYBOARD);
126
127 printk(KERN_INFO "input: keyboard(0x%lx): %s\n", data, kbd->dev.name);
128
129 return 0; 119 return 0;
130} 120}
131 121
@@ -134,7 +124,7 @@ static void dc_kbd_disconnect(struct maple_device *dev)
134{ 124{
135 struct dc_kbd *kbd = dev->private_data; 125 struct dc_kbd *kbd = dev->private_data;
136 126
137 input_unregister_device(&kbd->dev); 127 input_unregister_device(kbd->dev);
138 kfree(kbd); 128 kfree(kbd);
139} 129}
140 130
diff --git a/drivers/input/keyboard/newtonkbd.c b/drivers/input/keyboard/newtonkbd.c
index 2e8ce1613eec..d10983c521e6 100644
--- a/drivers/input/keyboard/newtonkbd.c
+++ b/drivers/input/keyboard/newtonkbd.c
@@ -57,11 +57,9 @@ static unsigned char nkbd_keycode[128] = {
57 KEY_LEFT, KEY_RIGHT, KEY_DOWN, KEY_UP, 0 57 KEY_LEFT, KEY_RIGHT, KEY_DOWN, KEY_UP, 0
58}; 58};
59 59
60static char *nkbd_name = "Newton Keyboard";
61
62struct nkbd { 60struct nkbd {
63 unsigned char keycode[128]; 61 unsigned char keycode[128];
64 struct input_dev dev; 62 struct input_dev *dev;
65 struct serio *serio; 63 struct serio *serio;
66 char phys[32]; 64 char phys[32];
67}; 65};
@@ -73,13 +71,13 @@ static irqreturn_t nkbd_interrupt(struct serio *serio,
73 71
74 /* invalid scan codes are probably the init sequence, so we ignore them */ 72 /* invalid scan codes are probably the init sequence, so we ignore them */
75 if (nkbd->keycode[data & NKBD_KEY]) { 73 if (nkbd->keycode[data & NKBD_KEY]) {
76 input_regs(&nkbd->dev, regs); 74 input_regs(nkbd->dev, regs);
77 input_report_key(&nkbd->dev, nkbd->keycode[data & NKBD_KEY], data & NKBD_PRESS); 75 input_report_key(nkbd->dev, nkbd->keycode[data & NKBD_KEY], data & NKBD_PRESS);
78 input_sync(&nkbd->dev); 76 input_sync(nkbd->dev);
79 } 77 }
80 78
81 else if (data == 0xe7) /* end of init sequence */ 79 else if (data == 0xe7) /* end of init sequence */
82 printk(KERN_INFO "input: %s on %s\n", nkbd_name, serio->phys); 80 printk(KERN_INFO "input: %s on %s\n", nkbd->dev->name, serio->phys);
83 return IRQ_HANDLED; 81 return IRQ_HANDLED;
84 82
85} 83}
@@ -87,62 +85,59 @@ static irqreturn_t nkbd_interrupt(struct serio *serio,
87static int nkbd_connect(struct serio *serio, struct serio_driver *drv) 85static int nkbd_connect(struct serio *serio, struct serio_driver *drv)
88{ 86{
89 struct nkbd *nkbd; 87 struct nkbd *nkbd;
88 struct input_dev *input_dev;
89 int err = -ENOMEM;
90 int i; 90 int i;
91 int err;
92
93 if (!(nkbd = kmalloc(sizeof(struct nkbd), GFP_KERNEL)))
94 return -ENOMEM;
95
96 memset(nkbd, 0, sizeof(struct nkbd));
97 91
98 nkbd->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REP); 92 nkbd = kzalloc(sizeof(struct nkbd), GFP_KERNEL);
93 input_dev = input_allocate_device();
94 if (!nkbd || !input_dev)
95 goto fail;
99 96
100 nkbd->serio = serio; 97 nkbd->serio = serio;
98 nkbd->dev = input_dev;
99 sprintf(nkbd->phys, "%s/input0", serio->phys);
100 memcpy(nkbd->keycode, nkbd_keycode, sizeof(nkbd->keycode));
101 101
102 init_input_dev(&nkbd->dev); 102 input_dev->name = "Newton Keyboard";
103 nkbd->dev.keycode = nkbd->keycode; 103 input_dev->phys = nkbd->phys;
104 nkbd->dev.keycodesize = sizeof(unsigned char); 104 input_dev->id.bustype = BUS_RS232;
105 nkbd->dev.keycodemax = ARRAY_SIZE(nkbd_keycode); 105 input_dev->id.vendor = SERIO_NEWTON;
106 nkbd->dev.private = nkbd; 106 input_dev->id.product = 0x0001;
107 input_dev->id.version = 0x0100;
108 input_dev->cdev.dev = &serio->dev;
109 input_dev->private = nkbd;
110
111 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
112 input_dev->keycode = nkbd->keycode;
113 input_dev->keycodesize = sizeof(unsigned char);
114 input_dev->keycodemax = ARRAY_SIZE(nkbd_keycode);
115 for (i = 0; i < 128; i++)
116 set_bit(nkbd->keycode[i], input_dev->keybit);
117 clear_bit(0, input_dev->keybit);
107 118
108 serio_set_drvdata(serio, nkbd); 119 serio_set_drvdata(serio, nkbd);
109 120
110 err = serio_open(serio, drv); 121 err = serio_open(serio, drv);
111 if (err) { 122 if (err)
112 serio_set_drvdata(serio, NULL); 123 goto fail;
113 kfree(nkbd);
114 return err;
115 }
116
117 memcpy(nkbd->keycode, nkbd_keycode, sizeof(nkbd->keycode));
118 for (i = 0; i < 128; i++)
119 set_bit(nkbd->keycode[i], nkbd->dev.keybit);
120 clear_bit(0, nkbd->dev.keybit);
121
122 sprintf(nkbd->phys, "%s/input0", serio->phys);
123
124 nkbd->dev.name = nkbd_name;
125 nkbd->dev.phys = nkbd->phys;
126 nkbd->dev.id.bustype = BUS_RS232;
127 nkbd->dev.id.vendor = SERIO_NEWTON;
128 nkbd->dev.id.product = 0x0001;
129 nkbd->dev.id.version = 0x0100;
130 nkbd->dev.dev = &serio->dev;
131
132 input_register_device(&nkbd->dev);
133
134 printk(KERN_INFO "input: %s on %s\n", nkbd_name, serio->phys);
135 124
125 input_register_device(nkbd->dev);
136 return 0; 126 return 0;
127
128 fail: serio_set_drvdata(serio, NULL);
129 input_free_device(input_dev);
130 kfree(nkbd);
131 return err;
137} 132}
138 133
139static void nkbd_disconnect(struct serio *serio) 134static void nkbd_disconnect(struct serio *serio)
140{ 135{
141 struct nkbd *nkbd = serio_get_drvdata(serio); 136 struct nkbd *nkbd = serio_get_drvdata(serio);
142 137
143 input_unregister_device(&nkbd->dev);
144 serio_close(serio); 138 serio_close(serio);
145 serio_set_drvdata(serio, NULL); 139 serio_set_drvdata(serio, NULL);
140 input_unregister_device(nkbd->dev);
146 kfree(nkbd); 141 kfree(nkbd);
147} 142}
148 143
diff --git a/drivers/input/keyboard/spitzkbd.c b/drivers/input/keyboard/spitzkbd.c
index 344f46005401..cee9c734a048 100644
--- a/drivers/input/keyboard/spitzkbd.c
+++ b/drivers/input/keyboard/spitzkbd.c
@@ -85,7 +85,7 @@ static int spitz_senses[] = {
85 85
86struct spitzkbd { 86struct spitzkbd {
87 unsigned char keycode[ARRAY_SIZE(spitzkbd_keycode)]; 87 unsigned char keycode[ARRAY_SIZE(spitzkbd_keycode)];
88 struct input_dev input; 88 struct input_dev *input;
89 char phys[32]; 89 char phys[32];
90 90
91 spinlock_t lock; 91 spinlock_t lock;
@@ -187,8 +187,7 @@ static void spitzkbd_scankeyboard(struct spitzkbd *spitzkbd_data, struct pt_regs
187 187
188 spin_lock_irqsave(&spitzkbd_data->lock, flags); 188 spin_lock_irqsave(&spitzkbd_data->lock, flags);
189 189
190 if (regs) 190 input_regs(spitzkbd_data->input, regs);
191 input_regs(&spitzkbd_data->input, regs);
192 191
193 num_pressed = 0; 192 num_pressed = 0;
194 for (col = 0; col < KB_COLS; col++) { 193 for (col = 0; col < KB_COLS; col++) {
@@ -210,7 +209,7 @@ static void spitzkbd_scankeyboard(struct spitzkbd *spitzkbd_data, struct pt_regs
210 scancode = SCANCODE(row, col); 209 scancode = SCANCODE(row, col);
211 pressed = rowd & KB_ROWMASK(row); 210 pressed = rowd & KB_ROWMASK(row);
212 211
213 input_report_key(&spitzkbd_data->input, spitzkbd_data->keycode[scancode], pressed); 212 input_report_key(spitzkbd_data->input, spitzkbd_data->keycode[scancode], pressed);
214 213
215 if (pressed) 214 if (pressed)
216 num_pressed++; 215 num_pressed++;
@@ -220,15 +219,15 @@ static void spitzkbd_scankeyboard(struct spitzkbd *spitzkbd_data, struct pt_regs
220 219
221 spitzkbd_activate_all(); 220 spitzkbd_activate_all();
222 221
223 input_report_key(&spitzkbd_data->input, SPITZ_KEY_SYNC, (GPLR(SPITZ_GPIO_SYNC) & GPIO_bit(SPITZ_GPIO_SYNC)) != 0 ); 222 input_report_key(spitzkbd_data->input, SPITZ_KEY_SYNC, (GPLR(SPITZ_GPIO_SYNC) & GPIO_bit(SPITZ_GPIO_SYNC)) != 0 );
224 input_report_key(&spitzkbd_data->input, KEY_SUSPEND, pwrkey); 223 input_report_key(spitzkbd_data->input, KEY_SUSPEND, pwrkey);
225 224
226 if (pwrkey && time_after(jiffies, spitzkbd_data->suspend_jiffies + msecs_to_jiffies(1000))) { 225 if (pwrkey && time_after(jiffies, spitzkbd_data->suspend_jiffies + msecs_to_jiffies(1000))) {
227 input_event(&spitzkbd_data->input, EV_PWR, KEY_SUSPEND, 1); 226 input_event(spitzkbd_data->input, EV_PWR, KEY_SUSPEND, 1);
228 spitzkbd_data->suspend_jiffies = jiffies; 227 spitzkbd_data->suspend_jiffies = jiffies;
229 } 228 }
230 229
231 input_sync(&spitzkbd_data->input); 230 input_sync(spitzkbd_data->input);
232 231
233 /* if any keys are pressed, enable the timer */ 232 /* if any keys are pressed, enable the timer */
234 if (num_pressed) 233 if (num_pressed)
@@ -259,6 +258,7 @@ static irqreturn_t spitzkbd_interrupt(int irq, void *dev_id, struct pt_regs *reg
259static void spitzkbd_timer_callback(unsigned long data) 258static void spitzkbd_timer_callback(unsigned long data)
260{ 259{
261 struct spitzkbd *spitzkbd_data = (struct spitzkbd *) data; 260 struct spitzkbd *spitzkbd_data = (struct spitzkbd *) data;
261
262 spitzkbd_scankeyboard(spitzkbd_data, NULL); 262 spitzkbd_scankeyboard(spitzkbd_data, NULL);
263} 263}
264 264
@@ -298,9 +298,9 @@ static void spitzkbd_hinge_timer(unsigned long data)
298 if (hinge_count >= HINGE_STABLE_COUNT) { 298 if (hinge_count >= HINGE_STABLE_COUNT) {
299 spin_lock_irqsave(&spitzkbd_data->lock, flags); 299 spin_lock_irqsave(&spitzkbd_data->lock, flags);
300 300
301 input_report_switch(&spitzkbd_data->input, SW_0, ((GPLR(SPITZ_GPIO_SWA) & GPIO_bit(SPITZ_GPIO_SWA)) != 0)); 301 input_report_switch(spitzkbd_data->input, SW_0, ((GPLR(SPITZ_GPIO_SWA) & GPIO_bit(SPITZ_GPIO_SWA)) != 0));
302 input_report_switch(&spitzkbd_data->input, SW_1, ((GPLR(SPITZ_GPIO_SWB) & GPIO_bit(SPITZ_GPIO_SWB)) != 0)); 302 input_report_switch(spitzkbd_data->input, SW_1, ((GPLR(SPITZ_GPIO_SWB) & GPIO_bit(SPITZ_GPIO_SWB)) != 0));
303 input_sync(&spitzkbd_data->input); 303 input_sync(spitzkbd_data->input);
304 304
305 spin_unlock_irqrestore(&spitzkbd_data->lock, flags); 305 spin_unlock_irqrestore(&spitzkbd_data->lock, flags);
306 } else { 306 } else {
@@ -309,34 +309,32 @@ static void spitzkbd_hinge_timer(unsigned long data)
309} 309}
310 310
311#ifdef CONFIG_PM 311#ifdef CONFIG_PM
312static int spitzkbd_suspend(struct device *dev, pm_message_t state, uint32_t level) 312static int spitzkbd_suspend(struct device *dev, pm_message_t state)
313{ 313{
314 if (level == SUSPEND_POWER_DOWN) { 314 int i;
315 int i; 315 struct spitzkbd *spitzkbd = dev_get_drvdata(dev);
316 struct spitzkbd *spitzkbd = dev_get_drvdata(dev); 316 spitzkbd->suspended = 1;
317 spitzkbd->suspended = 1; 317
318 318 /* Set Strobe lines as inputs - *except* strobe line 0 leave this
319 /* Set Strobe lines as inputs - *except* strobe line 0 leave this 319 enabled so we can detect a power button press for resume */
320 enabled so we can detect a power button press for resume */ 320 for (i = 1; i < SPITZ_KEY_STROBE_NUM; i++)
321 for (i = 1; i < SPITZ_KEY_STROBE_NUM; i++) 321 pxa_gpio_mode(spitz_strobes[i] | GPIO_IN);
322 pxa_gpio_mode(spitz_strobes[i] | GPIO_IN); 322
323 }
324 return 0; 323 return 0;
325} 324}
326 325
327static int spitzkbd_resume(struct device *dev, uint32_t level) 326static int spitzkbd_resume(struct device *dev)
328{ 327{
329 if (level == RESUME_POWER_ON) { 328 int i;
330 int i; 329 struct spitzkbd *spitzkbd = dev_get_drvdata(dev);
331 struct spitzkbd *spitzkbd = dev_get_drvdata(dev);
332 330
333 for (i = 0; i < SPITZ_KEY_STROBE_NUM; i++) 331 for (i = 0; i < SPITZ_KEY_STROBE_NUM; i++)
334 pxa_gpio_mode(spitz_strobes[i] | GPIO_OUT | GPIO_DFLT_HIGH); 332 pxa_gpio_mode(spitz_strobes[i] | GPIO_OUT | GPIO_DFLT_HIGH);
333
334 /* Upon resume, ignore the suspend key for a short while */
335 spitzkbd->suspend_jiffies = jiffies;
336 spitzkbd->suspended = 0;
335 337
336 /* Upon resume, ignore the suspend key for a short while */
337 spitzkbd->suspend_jiffies = jiffies;
338 spitzkbd->suspended = 0;
339 }
340 return 0; 338 return 0;
341} 339}
342#else 340#else
@@ -346,14 +344,21 @@ static int spitzkbd_resume(struct device *dev, uint32_t level)
346 344
347static int __init spitzkbd_probe(struct device *dev) 345static int __init spitzkbd_probe(struct device *dev)
348{ 346{
349 int i;
350 struct spitzkbd *spitzkbd; 347 struct spitzkbd *spitzkbd;
348 struct input_dev *input_dev;
349 int i;
351 350
352 spitzkbd = kzalloc(sizeof(struct spitzkbd), GFP_KERNEL); 351 spitzkbd = kzalloc(sizeof(struct spitzkbd), GFP_KERNEL);
353 if (!spitzkbd) 352 if (!spitzkbd)
354 return -ENOMEM; 353 return -ENOMEM;
355 354
356 dev_set_drvdata(dev,spitzkbd); 355 input_dev = input_allocate_device();
356 if (!input_dev) {
357 kfree(spitzkbd);
358 return -ENOMEM;
359 }
360
361 dev_set_drvdata(dev, spitzkbd);
357 strcpy(spitzkbd->phys, "spitzkbd/input0"); 362 strcpy(spitzkbd->phys, "spitzkbd/input0");
358 363
359 spin_lock_init(&spitzkbd->lock); 364 spin_lock_init(&spitzkbd->lock);
@@ -368,30 +373,34 @@ static int __init spitzkbd_probe(struct device *dev)
368 spitzkbd->htimer.function = spitzkbd_hinge_timer; 373 spitzkbd->htimer.function = spitzkbd_hinge_timer;
369 spitzkbd->htimer.data = (unsigned long) spitzkbd; 374 spitzkbd->htimer.data = (unsigned long) spitzkbd;
370 375
371 spitzkbd->suspend_jiffies=jiffies; 376 spitzkbd->suspend_jiffies = jiffies;
372 377
373 init_input_dev(&spitzkbd->input); 378 spitzkbd->input = input_dev;
374 spitzkbd->input.private = spitzkbd; 379
375 spitzkbd->input.name = "Spitz Keyboard"; 380 input_dev->private = spitzkbd;
376 spitzkbd->input.dev = dev; 381 input_dev->name = "Spitz Keyboard";
377 spitzkbd->input.phys = spitzkbd->phys; 382 input_dev->phys = spitzkbd->phys;
378 spitzkbd->input.id.bustype = BUS_HOST; 383 input_dev->cdev.dev = dev;
379 spitzkbd->input.id.vendor = 0x0001; 384
380 spitzkbd->input.id.product = 0x0001; 385 input_dev->id.bustype = BUS_HOST;
381 spitzkbd->input.id.version = 0x0100; 386 input_dev->id.vendor = 0x0001;
382 spitzkbd->input.evbit[0] = BIT(EV_KEY) | BIT(EV_REP) | BIT(EV_PWR) | BIT(EV_SW); 387 input_dev->id.product = 0x0001;
383 spitzkbd->input.keycode = spitzkbd->keycode; 388 input_dev->id.version = 0x0100;
384 spitzkbd->input.keycodesize = sizeof(unsigned char); 389
385 spitzkbd->input.keycodemax = ARRAY_SIZE(spitzkbd_keycode); 390 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP) | BIT(EV_PWR) | BIT(EV_SW);
391 input_dev->keycode = spitzkbd->keycode;
392 input_dev->keycodesize = sizeof(unsigned char);
393 input_dev->keycodemax = ARRAY_SIZE(spitzkbd_keycode);
386 394
387 memcpy(spitzkbd->keycode, spitzkbd_keycode, sizeof(spitzkbd->keycode)); 395 memcpy(spitzkbd->keycode, spitzkbd_keycode, sizeof(spitzkbd->keycode));
388 for (i = 0; i < ARRAY_SIZE(spitzkbd_keycode); i++) 396 for (i = 0; i < ARRAY_SIZE(spitzkbd_keycode); i++)
389 set_bit(spitzkbd->keycode[i], spitzkbd->input.keybit); 397 set_bit(spitzkbd->keycode[i], input_dev->keybit);
390 clear_bit(0, spitzkbd->input.keybit); 398 clear_bit(0, input_dev->keybit);
391 set_bit(SW_0, spitzkbd->input.swbit); 399 set_bit(SW_0, input_dev->swbit);
392 set_bit(SW_1, spitzkbd->input.swbit); 400 set_bit(SW_1, input_dev->swbit);
401
402 input_register_device(input_dev);
393 403
394 input_register_device(&spitzkbd->input);
395 mod_timer(&spitzkbd->htimer, jiffies + msecs_to_jiffies(HINGE_SCAN_INTERVAL)); 404 mod_timer(&spitzkbd->htimer, jiffies + msecs_to_jiffies(HINGE_SCAN_INTERVAL));
396 405
397 /* Setup sense interrupts - RisingEdge Detect, sense lines as inputs */ 406 /* Setup sense interrupts - RisingEdge Detect, sense lines as inputs */
@@ -444,7 +453,7 @@ static int spitzkbd_remove(struct device *dev)
444 del_timer_sync(&spitzkbd->htimer); 453 del_timer_sync(&spitzkbd->htimer);
445 del_timer_sync(&spitzkbd->timer); 454 del_timer_sync(&spitzkbd->timer);
446 455
447 input_unregister_device(&spitzkbd->input); 456 input_unregister_device(spitzkbd->input);
448 457
449 kfree(spitzkbd); 458 kfree(spitzkbd);
450 459
diff --git a/drivers/input/keyboard/sunkbd.c b/drivers/input/keyboard/sunkbd.c
index 4bae5d89348d..b15b6d8d4f83 100644
--- a/drivers/input/keyboard/sunkbd.c
+++ b/drivers/input/keyboard/sunkbd.c
@@ -76,13 +76,14 @@ static unsigned char sunkbd_keycode[128] = {
76 76
77struct sunkbd { 77struct sunkbd {
78 unsigned char keycode[128]; 78 unsigned char keycode[128];
79 struct input_dev dev; 79 struct input_dev *dev;
80 struct serio *serio; 80 struct serio *serio;
81 struct work_struct tq; 81 struct work_struct tq;
82 wait_queue_head_t wait; 82 wait_queue_head_t wait;
83 char name[64]; 83 char name[64];
84 char phys[32]; 84 char phys[32];
85 char type; 85 char type;
86 unsigned char enabled;
86 volatile s8 reset; 87 volatile s8 reset;
87 volatile s8 layout; 88 volatile s8 layout;
88}; 89};
@@ -124,10 +125,13 @@ static irqreturn_t sunkbd_interrupt(struct serio *serio,
124 break; 125 break;
125 126
126 default: 127 default:
128 if (!sunkbd->enabled)
129 break;
130
127 if (sunkbd->keycode[data & SUNKBD_KEY]) { 131 if (sunkbd->keycode[data & SUNKBD_KEY]) {
128 input_regs(&sunkbd->dev, regs); 132 input_regs(sunkbd->dev, regs);
129 input_report_key(&sunkbd->dev, sunkbd->keycode[data & SUNKBD_KEY], !(data & SUNKBD_RELEASE)); 133 input_report_key(sunkbd->dev, sunkbd->keycode[data & SUNKBD_KEY], !(data & SUNKBD_RELEASE));
130 input_sync(&sunkbd->dev); 134 input_sync(sunkbd->dev);
131 } else { 135 } else {
132 printk(KERN_WARNING "sunkbd.c: Unknown key (scancode %#x) %s.\n", 136 printk(KERN_WARNING "sunkbd.c: Unknown key (scancode %#x) %s.\n",
133 data & SUNKBD_KEY, data & SUNKBD_RELEASE ? "released" : "pressed"); 137 data & SUNKBD_KEY, data & SUNKBD_RELEASE ? "released" : "pressed");
@@ -184,7 +188,7 @@ static int sunkbd_initialize(struct sunkbd *sunkbd)
184 sunkbd->reset = -2; 188 sunkbd->reset = -2;
185 sunkbd->serio->write(sunkbd->serio, SUNKBD_CMD_RESET); 189 sunkbd->serio->write(sunkbd->serio, SUNKBD_CMD_RESET);
186 wait_event_interruptible_timeout(sunkbd->wait, sunkbd->reset >= 0, HZ); 190 wait_event_interruptible_timeout(sunkbd->wait, sunkbd->reset >= 0, HZ);
187 if (sunkbd->reset <0) 191 if (sunkbd->reset < 0)
188 return -1; 192 return -1;
189 193
190 sunkbd->type = sunkbd->reset; 194 sunkbd->type = sunkbd->reset;
@@ -213,10 +217,17 @@ static void sunkbd_reinit(void *data)
213 217
214 sunkbd->serio->write(sunkbd->serio, SUNKBD_CMD_SETLED); 218 sunkbd->serio->write(sunkbd->serio, SUNKBD_CMD_SETLED);
215 sunkbd->serio->write(sunkbd->serio, 219 sunkbd->serio->write(sunkbd->serio,
216 (!!test_bit(LED_CAPSL, sunkbd->dev.led) << 3) | (!!test_bit(LED_SCROLLL, sunkbd->dev.led) << 2) | 220 (!!test_bit(LED_CAPSL, sunkbd->dev->led) << 3) | (!!test_bit(LED_SCROLLL, sunkbd->dev->led) << 2) |
217 (!!test_bit(LED_COMPOSE, sunkbd->dev.led) << 1) | !!test_bit(LED_NUML, sunkbd->dev.led)); 221 (!!test_bit(LED_COMPOSE, sunkbd->dev->led) << 1) | !!test_bit(LED_NUML, sunkbd->dev->led));
218 sunkbd->serio->write(sunkbd->serio, SUNKBD_CMD_NOCLICK - !!test_bit(SND_CLICK, sunkbd->dev.snd)); 222 sunkbd->serio->write(sunkbd->serio, SUNKBD_CMD_NOCLICK - !!test_bit(SND_CLICK, sunkbd->dev->snd));
219 sunkbd->serio->write(sunkbd->serio, SUNKBD_CMD_BELLOFF - !!test_bit(SND_BELL, sunkbd->dev.snd)); 223 sunkbd->serio->write(sunkbd->serio, SUNKBD_CMD_BELLOFF - !!test_bit(SND_BELL, sunkbd->dev->snd));
224}
225
226static void sunkbd_enable(struct sunkbd *sunkbd, int enable)
227{
228 serio_pause_rx(sunkbd->serio);
229 sunkbd->enabled = 1;
230 serio_continue_rx(sunkbd->serio);
220} 231}
221 232
222/* 233/*
@@ -226,70 +237,64 @@ static void sunkbd_reinit(void *data)
226static int sunkbd_connect(struct serio *serio, struct serio_driver *drv) 237static int sunkbd_connect(struct serio *serio, struct serio_driver *drv)
227{ 238{
228 struct sunkbd *sunkbd; 239 struct sunkbd *sunkbd;
240 struct input_dev *input_dev;
241 int err = -ENOMEM;
229 int i; 242 int i;
230 int err;
231
232 if (!(sunkbd = kmalloc(sizeof(struct sunkbd), GFP_KERNEL)))
233 return -ENOMEM;
234 243
235 memset(sunkbd, 0, sizeof(struct sunkbd)); 244 sunkbd = kzalloc(sizeof(struct sunkbd), GFP_KERNEL);
236 245 input_dev = input_allocate_device();
237 init_input_dev(&sunkbd->dev); 246 if (!sunkbd || !input_dev)
238 init_waitqueue_head(&sunkbd->wait); 247 goto fail;
239
240 sunkbd->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_LED) | BIT(EV_SND) | BIT(EV_REP);
241 sunkbd->dev.ledbit[0] = BIT(LED_CAPSL) | BIT(LED_COMPOSE) | BIT(LED_SCROLLL) | BIT(LED_NUML);
242 sunkbd->dev.sndbit[0] = BIT(SND_CLICK) | BIT(SND_BELL);
243 248
244 sunkbd->serio = serio; 249 sunkbd->serio = serio;
245 250 sunkbd->dev = input_dev;
251 init_waitqueue_head(&sunkbd->wait);
246 INIT_WORK(&sunkbd->tq, sunkbd_reinit, sunkbd); 252 INIT_WORK(&sunkbd->tq, sunkbd_reinit, sunkbd);
247 253 snprintf(sunkbd->phys, sizeof(sunkbd->phys), "%s/input0", serio->phys);
248 sunkbd->dev.keycode = sunkbd->keycode;
249 sunkbd->dev.keycodesize = sizeof(unsigned char);
250 sunkbd->dev.keycodemax = ARRAY_SIZE(sunkbd_keycode);
251
252 sunkbd->dev.event = sunkbd_event;
253 sunkbd->dev.private = sunkbd;
254 254
255 serio_set_drvdata(serio, sunkbd); 255 serio_set_drvdata(serio, sunkbd);
256 256
257 err = serio_open(serio, drv); 257 err = serio_open(serio, drv);
258 if (err) { 258 if (err)
259 serio_set_drvdata(serio, NULL); 259 goto fail;
260 kfree(sunkbd);
261 return err;
262 }
263 260
264 if (sunkbd_initialize(sunkbd) < 0) { 261 if (sunkbd_initialize(sunkbd) < 0) {
265 serio_close(serio); 262 serio_close(serio);
266 serio_set_drvdata(serio, NULL); 263 goto fail;
267 kfree(sunkbd);
268 return -ENODEV;
269 } 264 }
270 265
271 sprintf(sunkbd->name, "Sun Type %d keyboard", sunkbd->type); 266 sprintf(sunkbd->name, "Sun Type %d keyboard", sunkbd->type);
272
273 memcpy(sunkbd->keycode, sunkbd_keycode, sizeof(sunkbd->keycode)); 267 memcpy(sunkbd->keycode, sunkbd_keycode, sizeof(sunkbd->keycode));
274 for (i = 0; i < 128; i++)
275 set_bit(sunkbd->keycode[i], sunkbd->dev.keybit);
276 clear_bit(0, sunkbd->dev.keybit);
277
278 sprintf(sunkbd->phys, "%s/input0", serio->phys);
279
280 sunkbd->dev.name = sunkbd->name;
281 sunkbd->dev.phys = sunkbd->phys;
282 sunkbd->dev.id.bustype = BUS_RS232;
283 sunkbd->dev.id.vendor = SERIO_SUNKBD;
284 sunkbd->dev.id.product = sunkbd->type;
285 sunkbd->dev.id.version = 0x0100;
286 sunkbd->dev.dev = &serio->dev;
287 268
288 input_register_device(&sunkbd->dev); 269 input_dev->name = sunkbd->name;
289 270 input_dev->phys = sunkbd->phys;
290 printk(KERN_INFO "input: %s on %s\n", sunkbd->name, serio->phys); 271 input_dev->id.bustype = BUS_RS232;
272 input_dev->id.vendor = SERIO_SUNKBD;
273 input_dev->id.product = sunkbd->type;
274 input_dev->id.version = 0x0100;
275 input_dev->cdev.dev = &serio->dev;
276 input_dev->private = sunkbd;
277 input_dev->event = sunkbd_event;
278
279 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_LED) | BIT(EV_SND) | BIT(EV_REP);
280 input_dev->ledbit[0] = BIT(LED_CAPSL) | BIT(LED_COMPOSE) | BIT(LED_SCROLLL) | BIT(LED_NUML);
281 input_dev->sndbit[0] = BIT(SND_CLICK) | BIT(SND_BELL);
282
283 input_dev->keycode = sunkbd->keycode;
284 input_dev->keycodesize = sizeof(unsigned char);
285 input_dev->keycodemax = ARRAY_SIZE(sunkbd_keycode);
286 for (i = 0; i < 128; i++)
287 set_bit(sunkbd->keycode[i], input_dev->keybit);
288 clear_bit(0, input_dev->keybit);
291 289
290 sunkbd_enable(sunkbd, 1);
291 input_register_device(sunkbd->dev);
292 return 0; 292 return 0;
293
294 fail: serio_set_drvdata(serio, NULL);
295 input_free_device(input_dev);
296 kfree(sunkbd);
297 return err;
293} 298}
294 299
295/* 300/*
@@ -299,7 +304,9 @@ static int sunkbd_connect(struct serio *serio, struct serio_driver *drv)
299static void sunkbd_disconnect(struct serio *serio) 304static void sunkbd_disconnect(struct serio *serio)
300{ 305{
301 struct sunkbd *sunkbd = serio_get_drvdata(serio); 306 struct sunkbd *sunkbd = serio_get_drvdata(serio);
302 input_unregister_device(&sunkbd->dev); 307
308 sunkbd_enable(sunkbd, 0);
309 input_unregister_device(sunkbd->dev);
303 serio_close(serio); 310 serio_close(serio);
304 serio_set_drvdata(serio, NULL); 311 serio_set_drvdata(serio, NULL);
305 kfree(sunkbd); 312 kfree(sunkbd);
diff --git a/drivers/input/keyboard/xtkbd.c b/drivers/input/keyboard/xtkbd.c
index 19eaec7789d1..4135e3e16c51 100644
--- a/drivers/input/keyboard/xtkbd.c
+++ b/drivers/input/keyboard/xtkbd.c
@@ -56,11 +56,9 @@ static unsigned char xtkbd_keycode[256] = {
56 106 56 106
57}; 57};
58 58
59static char *xtkbd_name = "XT Keyboard";
60
61struct xtkbd { 59struct xtkbd {
62 unsigned char keycode[256]; 60 unsigned char keycode[256];
63 struct input_dev dev; 61 struct input_dev *dev;
64 struct serio *serio; 62 struct serio *serio;
65 char phys[32]; 63 char phys[32];
66}; 64};
@@ -77,9 +75,9 @@ static irqreturn_t xtkbd_interrupt(struct serio *serio,
77 default: 75 default:
78 76
79 if (xtkbd->keycode[data & XTKBD_KEY]) { 77 if (xtkbd->keycode[data & XTKBD_KEY]) {
80 input_regs(&xtkbd->dev, regs); 78 input_regs(xtkbd->dev, regs);
81 input_report_key(&xtkbd->dev, xtkbd->keycode[data & XTKBD_KEY], !(data & XTKBD_RELEASE)); 79 input_report_key(xtkbd->dev, xtkbd->keycode[data & XTKBD_KEY], !(data & XTKBD_RELEASE));
82 input_sync(&xtkbd->dev); 80 input_sync(xtkbd->dev);
83 } else { 81 } else {
84 printk(KERN_WARNING "xtkbd.c: Unknown key (scancode %#x) %s.\n", 82 printk(KERN_WARNING "xtkbd.c: Unknown key (scancode %#x) %s.\n",
85 data & XTKBD_KEY, data & XTKBD_RELEASE ? "released" : "pressed"); 83 data & XTKBD_KEY, data & XTKBD_RELEASE ? "released" : "pressed");
@@ -91,62 +89,60 @@ static irqreturn_t xtkbd_interrupt(struct serio *serio,
91static int xtkbd_connect(struct serio *serio, struct serio_driver *drv) 89static int xtkbd_connect(struct serio *serio, struct serio_driver *drv)
92{ 90{
93 struct xtkbd *xtkbd; 91 struct xtkbd *xtkbd;
92 struct input_dev *input_dev;
93 int err = -ENOMEM;
94 int i; 94 int i;
95 int err;
96
97 if (!(xtkbd = kmalloc(sizeof(struct xtkbd), GFP_KERNEL)))
98 return -ENOMEM;
99
100 memset(xtkbd, 0, sizeof(struct xtkbd));
101 95
102 xtkbd->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REP); 96 xtkbd = kmalloc(sizeof(struct xtkbd), GFP_KERNEL);
97 input_dev = input_allocate_device();
98 if (!xtkbd || !input_dev)
99 goto fail;
103 100
104 xtkbd->serio = serio; 101 xtkbd->serio = serio;
102 xtkbd->dev = input_dev;
103 sprintf(xtkbd->phys, "%s/input0", serio->phys);
104 memcpy(xtkbd->keycode, xtkbd_keycode, sizeof(xtkbd->keycode));
105 105
106 init_input_dev(&xtkbd->dev); 106 input_dev->name = "XT Keyboard";
107 xtkbd->dev.keycode = xtkbd->keycode; 107 input_dev->phys = xtkbd->phys;
108 xtkbd->dev.keycodesize = sizeof(unsigned char); 108 input_dev->id.bustype = BUS_XTKBD;
109 xtkbd->dev.keycodemax = ARRAY_SIZE(xtkbd_keycode); 109 input_dev->id.vendor = 0x0001;
110 xtkbd->dev.private = xtkbd; 110 input_dev->id.product = 0x0001;
111 111 input_dev->id.version = 0x0100;
112 serio_set_drvdata(serio, xtkbd); 112 input_dev->cdev.dev = &serio->dev;
113 input_dev->private = xtkbd;
113 114
114 err = serio_open(serio, drv); 115 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
115 if (err) { 116 input_dev->keycode = xtkbd->keycode;
116 serio_set_drvdata(serio, NULL); 117 input_dev->keycodesize = sizeof(unsigned char);
117 kfree(xtkbd); 118 input_dev->keycodemax = ARRAY_SIZE(xtkbd_keycode);
118 return err;
119 }
120 119
121 memcpy(xtkbd->keycode, xtkbd_keycode, sizeof(xtkbd->keycode));
122 for (i = 0; i < 255; i++) 120 for (i = 0; i < 255; i++)
123 set_bit(xtkbd->keycode[i], xtkbd->dev.keybit); 121 set_bit(xtkbd->keycode[i], input_dev->keybit);
124 clear_bit(0, xtkbd->dev.keybit); 122 clear_bit(0, input_dev->keybit);
125
126 sprintf(xtkbd->phys, "%s/input0", serio->phys);
127
128 xtkbd->dev.name = xtkbd_name;
129 xtkbd->dev.phys = xtkbd->phys;
130 xtkbd->dev.id.bustype = BUS_XTKBD;
131 xtkbd->dev.id.vendor = 0x0001;
132 xtkbd->dev.id.product = 0x0001;
133 xtkbd->dev.id.version = 0x0100;
134 xtkbd->dev.dev = &serio->dev;
135 123
136 input_register_device(&xtkbd->dev); 124 serio_set_drvdata(serio, xtkbd);
137 125
138 printk(KERN_INFO "input: %s on %s\n", xtkbd_name, serio->phys); 126 err = serio_open(serio, drv);
127 if (err)
128 goto fail;
139 129
130 input_register_device(xtkbd->dev);
140 return 0; 131 return 0;
132
133 fail: serio_set_drvdata(serio, NULL);
134 input_free_device(input_dev);
135 kfree(xtkbd);
136 return err;
141} 137}
142 138
143static void xtkbd_disconnect(struct serio *serio) 139static void xtkbd_disconnect(struct serio *serio)
144{ 140{
145 struct xtkbd *xtkbd = serio_get_drvdata(serio); 141 struct xtkbd *xtkbd = serio_get_drvdata(serio);
146 142
147 input_unregister_device(&xtkbd->dev);
148 serio_close(serio); 143 serio_close(serio);
149 serio_set_drvdata(serio, NULL); 144 serio_set_drvdata(serio, NULL);
145 input_unregister_device(xtkbd->dev);
150 kfree(xtkbd); 146 kfree(xtkbd);
151} 147}
152 148
diff --git a/drivers/input/misc/m68kspkr.c b/drivers/input/misc/m68kspkr.c
index 64abdd98d482..04489ad7702a 100644
--- a/drivers/input/misc/m68kspkr.c
+++ b/drivers/input/misc/m68kspkr.c
@@ -24,9 +24,7 @@ MODULE_AUTHOR("Richard Zidlicky <rz@linux-m68k.org>");
24MODULE_DESCRIPTION("m68k beeper driver"); 24MODULE_DESCRIPTION("m68k beeper driver");
25MODULE_LICENSE("GPL"); 25MODULE_LICENSE("GPL");
26 26
27static char m68kspkr_name[] = "m68k beeper"; 27static struct input_dev *m68kspkr_dev;
28static char m68kspkr_phys[] = "m68k/generic";
29static struct input_dev m68kspkr_dev;
30 28
31static int m68kspkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) 29static int m68kspkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
32{ 30{
@@ -51,32 +49,34 @@ static int m68kspkr_event(struct input_dev *dev, unsigned int type, unsigned int
51 49
52static int __init m68kspkr_init(void) 50static int __init m68kspkr_init(void)
53{ 51{
54 if (!mach_beep){ 52 if (!mach_beep) {
55 printk("%s: no lowlevel beep support\n", m68kspkr_name); 53 printk(KERN_INFO "m68kspkr: no lowlevel beep support\n");
56 return -1; 54 return -ENODEV;
57 } 55 }
58 56
59 m68kspkr_dev.evbit[0] = BIT(EV_SND); 57 m68kspkr_dev = input_allocate_device();
60 m68kspkr_dev.sndbit[0] = BIT(SND_BELL) | BIT(SND_TONE); 58 if (!m68kspkr_dev)
61 m68kspkr_dev.event = m68kspkr_event; 59 return -ENOMEM;
62 60
63 m68kspkr_dev.name = m68kspkr_name; 61 m68kspkr_dev->name = "m68k beeper";
64 m68kspkr_dev.phys = m68kspkr_phys; 62 m68kspkr_dev->phys = "m68k/generic";
65 m68kspkr_dev.id.bustype = BUS_HOST; 63 m68kspkr_dev->id.bustype = BUS_HOST;
66 m68kspkr_dev.id.vendor = 0x001f; 64 m68kspkr_dev->id.vendor = 0x001f;
67 m68kspkr_dev.id.product = 0x0001; 65 m68kspkr_dev->id.product = 0x0001;
68 m68kspkr_dev.id.version = 0x0100; 66 m68kspkr_dev->id.version = 0x0100;
69 67
70 input_register_device(&m68kspkr_dev); 68 m68kspkr_dev->evbit[0] = BIT(EV_SND);
69 m68kspkr_dev->sndbit[0] = BIT(SND_BELL) | BIT(SND_TONE);
70 m68kspkr_dev->event = m68kspkr_event;
71 71
72 printk(KERN_INFO "input: %s\n", m68kspkr_name); 72 input_register_device(m68kspkr_dev);
73 73
74 return 0; 74 return 0;
75} 75}
76 76
77static void __exit m68kspkr_exit(void) 77static void __exit m68kspkr_exit(void)
78{ 78{
79 input_unregister_device(&m68kspkr_dev); 79 input_unregister_device(m68kspkr_dev);
80} 80}
81 81
82module_init(m68kspkr_init); 82module_init(m68kspkr_init);
diff --git a/drivers/input/misc/pcspkr.c b/drivers/input/misc/pcspkr.c
index 3013194f462b..e34633c37fdd 100644
--- a/drivers/input/misc/pcspkr.c
+++ b/drivers/input/misc/pcspkr.c
@@ -23,9 +23,7 @@ MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
23MODULE_DESCRIPTION("PC Speaker beeper driver"); 23MODULE_DESCRIPTION("PC Speaker beeper driver");
24MODULE_LICENSE("GPL"); 24MODULE_LICENSE("GPL");
25 25
26static char pcspkr_name[] = "PC Speaker"; 26static struct input_dev *pcspkr_dev;
27static char pcspkr_phys[] = "isa0061/input0";
28static struct input_dev pcspkr_dev;
29 27
30static DEFINE_SPINLOCK(i8253_beep_lock); 28static DEFINE_SPINLOCK(i8253_beep_lock);
31 29
@@ -68,27 +66,29 @@ static int pcspkr_event(struct input_dev *dev, unsigned int type, unsigned int c
68 66
69static int __init pcspkr_init(void) 67static int __init pcspkr_init(void)
70{ 68{
71 pcspkr_dev.evbit[0] = BIT(EV_SND); 69 pcspkr_dev = input_allocate_device();
72 pcspkr_dev.sndbit[0] = BIT(SND_BELL) | BIT(SND_TONE); 70 if (!pcspkr_dev)
73 pcspkr_dev.event = pcspkr_event; 71 return -ENOMEM;
74 72
75 pcspkr_dev.name = pcspkr_name; 73 pcspkr_dev->name = "PC Speaker";
76 pcspkr_dev.phys = pcspkr_phys; 74 pcspkr_dev->name = "isa0061/input0";
77 pcspkr_dev.id.bustype = BUS_ISA; 75 pcspkr_dev->id.bustype = BUS_ISA;
78 pcspkr_dev.id.vendor = 0x001f; 76 pcspkr_dev->id.vendor = 0x001f;
79 pcspkr_dev.id.product = 0x0001; 77 pcspkr_dev->id.product = 0x0001;
80 pcspkr_dev.id.version = 0x0100; 78 pcspkr_dev->id.version = 0x0100;
81 79
82 input_register_device(&pcspkr_dev); 80 pcspkr_dev->evbit[0] = BIT(EV_SND);
81 pcspkr_dev->sndbit[0] = BIT(SND_BELL) | BIT(SND_TONE);
82 pcspkr_dev->event = pcspkr_event;
83 83
84 printk(KERN_INFO "input: %s\n", pcspkr_name); 84 input_register_device(pcspkr_dev);
85 85
86 return 0; 86 return 0;
87} 87}
88 88
89static void __exit pcspkr_exit(void) 89static void __exit pcspkr_exit(void)
90{ 90{
91 input_unregister_device(&pcspkr_dev); 91 input_unregister_device(pcspkr_dev);
92 /* turn off the speaker */ 92 /* turn off the speaker */
93 pcspkr_event(NULL, EV_SND, SND_BELL, 0); 93 pcspkr_event(NULL, EV_SND, SND_BELL, 0);
94} 94}
diff --git a/drivers/input/misc/sparcspkr.c b/drivers/input/misc/sparcspkr.c
index cdc3fb3d5f46..5778220a18d2 100644
--- a/drivers/input/misc/sparcspkr.c
+++ b/drivers/input/misc/sparcspkr.c
@@ -17,28 +17,24 @@
17#endif 17#endif
18 18
19MODULE_AUTHOR("David S. Miller <davem@redhat.com>"); 19MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
20MODULE_DESCRIPTION("PC Speaker beeper driver"); 20MODULE_DESCRIPTION("Sparc Speaker beeper driver");
21MODULE_LICENSE("GPL"); 21MODULE_LICENSE("GPL");
22 22
23static unsigned long beep_iobase; 23static unsigned long beep_iobase;
24 24static struct input_dev *sparcspkr_dev;
25static char *sparcspkr_isa_name = "Sparc ISA Speaker";
26static char *sparcspkr_ebus_name = "Sparc EBUS Speaker";
27static char *sparcspkr_phys = "sparc/input0";
28static struct input_dev sparcspkr_dev;
29 25
30DEFINE_SPINLOCK(beep_lock); 26DEFINE_SPINLOCK(beep_lock);
31 27
32static void __init init_sparcspkr_struct(void) 28static void __init init_sparcspkr_struct(void)
33{ 29{
34 sparcspkr_dev.evbit[0] = BIT(EV_SND); 30 sparcspkr_dev->evbit[0] = BIT(EV_SND);
35 sparcspkr_dev.sndbit[0] = BIT(SND_BELL) | BIT(SND_TONE); 31 sparcspkr_dev->sndbit[0] = BIT(SND_BELL) | BIT(SND_TONE);
36 32
37 sparcspkr_dev.phys = sparcspkr_phys; 33 sparcspkr_dev->phys = "sparc/input0";
38 sparcspkr_dev.id.bustype = BUS_ISA; 34 sparcspkr_dev->id.bustype = BUS_ISA;
39 sparcspkr_dev.id.vendor = 0x001f; 35 sparcspkr_dev->id.vendor = 0x001f;
40 sparcspkr_dev.id.product = 0x0001; 36 sparcspkr_dev->id.product = 0x0001;
41 sparcspkr_dev.id.version = 0x0100; 37 sparcspkr_dev->id.version = 0x0100;
42} 38}
43 39
44static int ebus_spkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) 40static int ebus_spkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
@@ -84,14 +80,15 @@ static int __init init_ebus_beep(struct linux_ebus_device *edev)
84{ 80{
85 beep_iobase = edev->resource[0].start; 81 beep_iobase = edev->resource[0].start;
86 82
87 init_sparcspkr_struct(); 83 sparcspkr_dev = input_allocate_device();
84 if (!sparcspkr_dev)
85 return -ENOMEM;
88 86
89 sparcspkr_dev.name = sparcspkr_ebus_name; 87 sparcspkr_dev->name = "Sparc EBUS Speaker";
90 sparcspkr_dev.event = ebus_spkr_event; 88 sparcspkr_dev->event = ebus_spkr_event;
91 89
92 input_register_device(&sparcspkr_dev); 90 input_register_device(sparcspkr_dev);
93 91
94 printk(KERN_INFO "input: %s\n", sparcspkr_ebus_name);
95 return 0; 92 return 0;
96} 93}
97 94
@@ -137,15 +134,17 @@ static int __init init_isa_beep(struct sparc_isa_device *isa_dev)
137{ 134{
138 beep_iobase = isa_dev->resource.start; 135 beep_iobase = isa_dev->resource.start;
139 136
137 sparcspkr_dev = input_allocate_device();
138 if (!sparcspkr_dev)
139 return -ENOMEM;
140
140 init_sparcspkr_struct(); 141 init_sparcspkr_struct();
141 142
142 sparcspkr_dev.name = sparcspkr_isa_name; 143 sparcspkr_dev->name = "Sparc ISA Speaker";
143 sparcspkr_dev.event = isa_spkr_event; 144 sparcspkr_dev->event = isa_spkr_event;
144 sparcspkr_dev.id.bustype = BUS_ISA;
145 145
146 input_register_device(&sparcspkr_dev); 146 input_register_device(&sparcspkr_dev);
147 147
148 printk(KERN_INFO "input: %s\n", sparcspkr_isa_name);
149 return 0; 148 return 0;
150} 149}
151#endif 150#endif
@@ -182,7 +181,7 @@ static int __init sparcspkr_init(void)
182 181
183static void __exit sparcspkr_exit(void) 182static void __exit sparcspkr_exit(void)
184{ 183{
185 input_unregister_device(&sparcspkr_dev); 184 input_unregister_device(sparcspkr_dev);
186} 185}
187 186
188module_init(sparcspkr_init); 187module_init(sparcspkr_init);
diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
index b20783f9748a..4acc7fd4cd0f 100644
--- a/drivers/input/mouse/alps.c
+++ b/drivers/input/mouse/alps.c
@@ -79,8 +79,8 @@ static void alps_process_packet(struct psmouse *psmouse, struct pt_regs *regs)
79{ 79{
80 struct alps_data *priv = psmouse->private; 80 struct alps_data *priv = psmouse->private;
81 unsigned char *packet = psmouse->packet; 81 unsigned char *packet = psmouse->packet;
82 struct input_dev *dev = &psmouse->dev; 82 struct input_dev *dev = psmouse->dev;
83 struct input_dev *dev2 = &priv->dev2; 83 struct input_dev *dev2 = priv->dev2;
84 int x, y, z, ges, fin, left, right, middle; 84 int x, y, z, ges, fin, left, right, middle;
85 int back = 0, forward = 0; 85 int back = 0, forward = 0;
86 86
@@ -379,20 +379,24 @@ static int alps_reconnect(struct psmouse *psmouse)
379static void alps_disconnect(struct psmouse *psmouse) 379static void alps_disconnect(struct psmouse *psmouse)
380{ 380{
381 struct alps_data *priv = psmouse->private; 381 struct alps_data *priv = psmouse->private;
382
382 psmouse_reset(psmouse); 383 psmouse_reset(psmouse);
383 input_unregister_device(&priv->dev2); 384 input_unregister_device(priv->dev2);
384 kfree(priv); 385 kfree(priv);
385} 386}
386 387
387int alps_init(struct psmouse *psmouse) 388int alps_init(struct psmouse *psmouse)
388{ 389{
389 struct alps_data *priv; 390 struct alps_data *priv;
391 struct input_dev *dev1 = psmouse->dev, *dev2;
390 int version; 392 int version;
391 393
392 psmouse->private = priv = kmalloc(sizeof(struct alps_data), GFP_KERNEL); 394 psmouse->private = priv = kzalloc(sizeof(struct alps_data), GFP_KERNEL);
393 if (!priv) 395 dev2 = input_allocate_device();
396 if (!priv || !dev2)
394 goto init_fail; 397 goto init_fail;
395 memset(priv, 0, sizeof(struct alps_data)); 398
399 priv->dev2 = dev2;
396 400
397 if (!(priv->i = alps_get_model(psmouse, &version))) 401 if (!(priv->i = alps_get_model(psmouse, &version)))
398 goto init_fail; 402 goto init_fail;
@@ -411,41 +415,39 @@ int alps_init(struct psmouse *psmouse)
411 if ((priv->i->flags & ALPS_PASS) && alps_passthrough_mode(psmouse, 0)) 415 if ((priv->i->flags & ALPS_PASS) && alps_passthrough_mode(psmouse, 0))
412 goto init_fail; 416 goto init_fail;
413 417
414 psmouse->dev.evbit[LONG(EV_KEY)] |= BIT(EV_KEY); 418 dev1->evbit[LONG(EV_KEY)] |= BIT(EV_KEY);
415 psmouse->dev.keybit[LONG(BTN_TOUCH)] |= BIT(BTN_TOUCH); 419 dev1->keybit[LONG(BTN_TOUCH)] |= BIT(BTN_TOUCH);
416 psmouse->dev.keybit[LONG(BTN_TOOL_FINGER)] |= BIT(BTN_TOOL_FINGER); 420 dev1->keybit[LONG(BTN_TOOL_FINGER)] |= BIT(BTN_TOOL_FINGER);
417 psmouse->dev.keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT); 421 dev1->keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
418 422
419 psmouse->dev.evbit[LONG(EV_ABS)] |= BIT(EV_ABS); 423 dev1->evbit[LONG(EV_ABS)] |= BIT(EV_ABS);
420 input_set_abs_params(&psmouse->dev, ABS_X, 0, 1023, 0, 0); 424 input_set_abs_params(dev1, ABS_X, 0, 1023, 0, 0);
421 input_set_abs_params(&psmouse->dev, ABS_Y, 0, 767, 0, 0); 425 input_set_abs_params(dev1, ABS_Y, 0, 767, 0, 0);
422 input_set_abs_params(&psmouse->dev, ABS_PRESSURE, 0, 127, 0, 0); 426 input_set_abs_params(dev1, ABS_PRESSURE, 0, 127, 0, 0);
423 427
424 if (priv->i->flags & ALPS_WHEEL) { 428 if (priv->i->flags & ALPS_WHEEL) {
425 psmouse->dev.evbit[LONG(EV_REL)] |= BIT(EV_REL); 429 dev1->evbit[LONG(EV_REL)] |= BIT(EV_REL);
426 psmouse->dev.relbit[LONG(REL_WHEEL)] |= BIT(REL_WHEEL); 430 dev1->relbit[LONG(REL_WHEEL)] |= BIT(REL_WHEEL);
427 } 431 }
428 432
429 if (priv->i->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) { 433 if (priv->i->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) {
430 psmouse->dev.keybit[LONG(BTN_FORWARD)] |= BIT(BTN_FORWARD); 434 dev1->keybit[LONG(BTN_FORWARD)] |= BIT(BTN_FORWARD);
431 psmouse->dev.keybit[LONG(BTN_BACK)] |= BIT(BTN_BACK); 435 dev1->keybit[LONG(BTN_BACK)] |= BIT(BTN_BACK);
432 } 436 }
433 437
434 sprintf(priv->phys, "%s/input1", psmouse->ps2dev.serio->phys); 438 sprintf(priv->phys, "%s/input1", psmouse->ps2dev.serio->phys);
435 priv->dev2.phys = priv->phys; 439 dev2->phys = priv->phys;
436 priv->dev2.name = (priv->i->flags & ALPS_DUALPOINT) ? "DualPoint Stick" : "PS/2 Mouse"; 440 dev2->name = (priv->i->flags & ALPS_DUALPOINT) ? "DualPoint Stick" : "PS/2 Mouse";
437 priv->dev2.id.bustype = BUS_I8042; 441 dev2->id.bustype = BUS_I8042;
438 priv->dev2.id.vendor = 0x0002; 442 dev2->id.vendor = 0x0002;
439 priv->dev2.id.product = PSMOUSE_ALPS; 443 dev2->id.product = PSMOUSE_ALPS;
440 priv->dev2.id.version = 0x0000; 444 dev2->id.version = 0x0000;
441
442 priv->dev2.evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
443 priv->dev2.relbit[LONG(REL_X)] |= BIT(REL_X) | BIT(REL_Y);
444 priv->dev2.keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
445 445
446 input_register_device(&priv->dev2); 446 dev2->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
447 dev2->relbit[LONG(REL_X)] |= BIT(REL_X) | BIT(REL_Y);
448 dev2->keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
447 449
448 printk(KERN_INFO "input: %s on %s\n", priv->dev2.name, psmouse->ps2dev.serio->phys); 450 input_register_device(priv->dev2);
449 451
450 psmouse->protocol_handler = alps_process_byte; 452 psmouse->protocol_handler = alps_process_byte;
451 psmouse->disconnect = alps_disconnect; 453 psmouse->disconnect = alps_disconnect;
@@ -455,6 +457,7 @@ int alps_init(struct psmouse *psmouse)
455 return 0; 457 return 0;
456 458
457init_fail: 459init_fail:
460 input_free_device(dev2);
458 kfree(priv); 461 kfree(priv);
459 return -1; 462 return -1;
460} 463}
diff --git a/drivers/input/mouse/alps.h b/drivers/input/mouse/alps.h
index aba103dd65b7..e428f8d5d12e 100644
--- a/drivers/input/mouse/alps.h
+++ b/drivers/input/mouse/alps.h
@@ -22,7 +22,7 @@ struct alps_model_info {
22}; 22};
23 23
24struct alps_data { 24struct alps_data {
25 struct input_dev dev2; /* Relative device */ 25 struct input_dev *dev2; /* Relative device */
26 char name[32]; /* Name */ 26 char name[32]; /* Name */
27 char phys[32]; /* Phys */ 27 char phys[32]; /* Phys */
28 struct alps_model_info *i; /* Info */ 28 struct alps_model_info *i; /* Info */
diff --git a/drivers/input/mouse/amimouse.c b/drivers/input/mouse/amimouse.c
index e994849efb8f..d13d4c8fe3c5 100644
--- a/drivers/input/mouse/amimouse.c
+++ b/drivers/input/mouse/amimouse.c
@@ -34,10 +34,7 @@ MODULE_DESCRIPTION("Amiga mouse driver");
34MODULE_LICENSE("GPL"); 34MODULE_LICENSE("GPL");
35 35
36static int amimouse_lastx, amimouse_lasty; 36static int amimouse_lastx, amimouse_lasty;
37static struct input_dev amimouse_dev; 37static struct input_dev *amimouse_dev;
38
39static char *amimouse_name = "Amiga mouse";
40static char *amimouse_phys = "amimouse/input0";
41 38
42static irqreturn_t amimouse_interrupt(int irq, void *dummy, struct pt_regs *fp) 39static irqreturn_t amimouse_interrupt(int irq, void *dummy, struct pt_regs *fp)
43{ 40{
@@ -62,16 +59,16 @@ static irqreturn_t amimouse_interrupt(int irq, void *dummy, struct pt_regs *fp)
62 59
63 potgor = custom.potgor; 60 potgor = custom.potgor;
64 61
65 input_regs(&amimouse_dev, fp); 62 input_regs(amimouse_dev, fp);
66 63
67 input_report_rel(&amimouse_dev, REL_X, dx); 64 input_report_rel(amimouse_dev, REL_X, dx);
68 input_report_rel(&amimouse_dev, REL_Y, dy); 65 input_report_rel(amimouse_dev, REL_Y, dy);
69 66
70 input_report_key(&amimouse_dev, BTN_LEFT, ciaa.pra & 0x40); 67 input_report_key(amimouse_dev, BTN_LEFT, ciaa.pra & 0x40);
71 input_report_key(&amimouse_dev, BTN_MIDDLE, potgor & 0x0100); 68 input_report_key(amimouse_dev, BTN_MIDDLE, potgor & 0x0100);
72 input_report_key(&amimouse_dev, BTN_RIGHT, potgor & 0x0400); 69 input_report_key(amimouse_dev, BTN_RIGHT, potgor & 0x0400);
73 70
74 input_sync(&amimouse_dev); 71 input_sync(amimouse_dev);
75 72
76 return IRQ_HANDLED; 73 return IRQ_HANDLED;
77} 74}
@@ -103,28 +100,30 @@ static int __init amimouse_init(void)
103 if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(AMI_MOUSE)) 100 if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(AMI_MOUSE))
104 return -ENODEV; 101 return -ENODEV;
105 102
106 amimouse_dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REL); 103 if (!(amimouse_dev = input_allocate_device()))
107 amimouse_dev.relbit[0] = BIT(REL_X) | BIT(REL_Y); 104 return -ENOMEM;
108 amimouse_dev.keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT); 105
109 amimouse_dev.open = amimouse_open; 106 amimouse_dev->name = "Amiga mouse";
110 amimouse_dev.close = amimouse_close; 107 amimouse_dev->phys = "amimouse/input0";
108 amimouse_dev->id.bustype = BUS_AMIGA;
109 amimouse_dev->id.vendor = 0x0001;
110 amimouse_dev->id.product = 0x0002;
111 amimouse_dev->id.version = 0x0100;
111 112
112 amimouse_dev.name = amimouse_name; 113 amimouse_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
113 amimouse_dev.phys = amimouse_phys; 114 amimouse_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y);
114 amimouse_dev.id.bustype = BUS_AMIGA; 115 amimouse_dev->keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
115 amimouse_dev.id.vendor = 0x0001; 116 amimouse_dev->open = amimouse_open;
116 amimouse_dev.id.product = 0x0002; 117 amimouse_dev->close = amimouse_close;
117 amimouse_dev.id.version = 0x0100;
118 118
119 input_register_device(&amimouse_dev); 119 input_register_device(amimouse_dev);
120 120
121 printk(KERN_INFO "input: %s at joy0dat\n", amimouse_name);
122 return 0; 121 return 0;
123} 122}
124 123
125static void __exit amimouse_exit(void) 124static void __exit amimouse_exit(void)
126{ 125{
127 input_unregister_device(&amimouse_dev); 126 input_unregister_device(amimouse_dev);
128} 127}
129 128
130module_init(amimouse_init); 129module_init(amimouse_init);
diff --git a/drivers/input/mouse/inport.c b/drivers/input/mouse/inport.c
index 1f62c0134010..afc66f56df43 100644
--- a/drivers/input/mouse/inport.c
+++ b/drivers/input/mouse/inport.c
@@ -87,40 +87,7 @@ MODULE_PARM_DESC(irq, "IRQ number (5=default)");
87 87
88__obsolete_setup("inport_irq="); 88__obsolete_setup("inport_irq=");
89 89
90static irqreturn_t inport_interrupt(int irq, void *dev_id, struct pt_regs *regs); 90static struct input_dev *inport_dev;
91
92static int inport_open(struct input_dev *dev)
93{
94 if (request_irq(inport_irq, inport_interrupt, 0, "inport", NULL))
95 return -EBUSY;
96 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
97 outb(INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT);
98
99 return 0;
100}
101
102static void inport_close(struct input_dev *dev)
103{
104 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
105 outb(INPORT_MODE_BASE, INPORT_DATA_PORT);
106 free_irq(inport_irq, NULL);
107}
108
109static struct input_dev inport_dev = {
110 .evbit = { BIT(EV_KEY) | BIT(EV_REL) },
111 .keybit = { [LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT) },
112 .relbit = { BIT(REL_X) | BIT(REL_Y) },
113 .open = inport_open,
114 .close = inport_close,
115 .name = INPORT_NAME,
116 .phys = "isa023c/input0",
117 .id = {
118 .bustype = BUS_ISA,
119 .vendor = INPORT_VENDOR,
120 .product = 0x0001,
121 .version = 0x0100,
122 },
123};
124 91
125static irqreturn_t inport_interrupt(int irq, void *dev_id, struct pt_regs *regs) 92static irqreturn_t inport_interrupt(int irq, void *dev_id, struct pt_regs *regs)
126{ 93{
@@ -129,31 +96,48 @@ static irqreturn_t inport_interrupt(int irq, void *dev_id, struct pt_regs *regs)
129 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT); 96 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
130 outb(INPORT_MODE_HOLD | INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT); 97 outb(INPORT_MODE_HOLD | INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT);
131 98
132 input_regs(&inport_dev, regs); 99 input_regs(inport_dev, regs);
133 100
134 outb(INPORT_REG_X, INPORT_CONTROL_PORT); 101 outb(INPORT_REG_X, INPORT_CONTROL_PORT);
135 input_report_rel(&inport_dev, REL_X, inb(INPORT_DATA_PORT)); 102 input_report_rel(inport_dev, REL_X, inb(INPORT_DATA_PORT));
136 103
137 outb(INPORT_REG_Y, INPORT_CONTROL_PORT); 104 outb(INPORT_REG_Y, INPORT_CONTROL_PORT);
138 input_report_rel(&inport_dev, REL_Y, inb(INPORT_DATA_PORT)); 105 input_report_rel(inport_dev, REL_Y, inb(INPORT_DATA_PORT));
139 106
140 outb(INPORT_REG_BTNS, INPORT_CONTROL_PORT); 107 outb(INPORT_REG_BTNS, INPORT_CONTROL_PORT);
141 buttons = inb(INPORT_DATA_PORT); 108 buttons = inb(INPORT_DATA_PORT);
142 109
143 input_report_key(&inport_dev, BTN_MIDDLE, buttons & 1); 110 input_report_key(inport_dev, BTN_MIDDLE, buttons & 1);
144 input_report_key(&inport_dev, BTN_LEFT, buttons & 2); 111 input_report_key(inport_dev, BTN_LEFT, buttons & 2);
145 input_report_key(&inport_dev, BTN_RIGHT, buttons & 4); 112 input_report_key(inport_dev, BTN_RIGHT, buttons & 4);
146 113
147 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT); 114 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
148 outb(INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT); 115 outb(INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT);
149 116
150 input_sync(&inport_dev); 117 input_sync(inport_dev);
151 return IRQ_HANDLED; 118 return IRQ_HANDLED;
152} 119}
153 120
121static int inport_open(struct input_dev *dev)
122{
123 if (request_irq(inport_irq, inport_interrupt, 0, "inport", NULL))
124 return -EBUSY;
125 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
126 outb(INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT);
127
128 return 0;
129}
130
131static void inport_close(struct input_dev *dev)
132{
133 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
134 outb(INPORT_MODE_BASE, INPORT_DATA_PORT);
135 free_irq(inport_irq, NULL);
136}
137
154static int __init inport_init(void) 138static int __init inport_init(void)
155{ 139{
156 unsigned char a,b,c; 140 unsigned char a, b, c;
157 141
158 if (!request_region(INPORT_BASE, INPORT_EXTENT, "inport")) { 142 if (!request_region(INPORT_BASE, INPORT_EXTENT, "inport")) {
159 printk(KERN_ERR "inport.c: Can't allocate ports at %#x\n", INPORT_BASE); 143 printk(KERN_ERR "inport.c: Can't allocate ports at %#x\n", INPORT_BASE);
@@ -163,26 +147,44 @@ static int __init inport_init(void)
163 a = inb(INPORT_SIGNATURE_PORT); 147 a = inb(INPORT_SIGNATURE_PORT);
164 b = inb(INPORT_SIGNATURE_PORT); 148 b = inb(INPORT_SIGNATURE_PORT);
165 c = inb(INPORT_SIGNATURE_PORT); 149 c = inb(INPORT_SIGNATURE_PORT);
166 if (( a == b ) || ( a != c )) { 150 if (a == b || a != c) {
167 release_region(INPORT_BASE, INPORT_EXTENT); 151 release_region(INPORT_BASE, INPORT_EXTENT);
168 printk(KERN_ERR "inport.c: Didn't find InPort mouse at %#x\n", INPORT_BASE); 152 printk(KERN_ERR "inport.c: Didn't find InPort mouse at %#x\n", INPORT_BASE);
169 return -ENODEV; 153 return -ENODEV;
170 } 154 }
171 155
156 if (!(inport_dev = input_allocate_device())) {
157 printk(KERN_ERR "inport.c: Not enough memory for input device\n");
158 release_region(INPORT_BASE, INPORT_EXTENT);
159 return -ENOMEM;
160 }
161
162 inport_dev->name = INPORT_NAME;
163 inport_dev->phys = "isa023c/input0";
164 inport_dev->id.bustype = BUS_ISA;
165 inport_dev->id.vendor = INPORT_VENDOR;
166 inport_dev->id.product = 0x0001;
167 inport_dev->id.version = 0x0100;
168
169 inport_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
170 inport_dev->keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
171 inport_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y);
172
173 inport_dev->open = inport_open;
174 inport_dev->close = inport_close;
175
172 outb(INPORT_RESET, INPORT_CONTROL_PORT); 176 outb(INPORT_RESET, INPORT_CONTROL_PORT);
173 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT); 177 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
174 outb(INPORT_MODE_BASE, INPORT_DATA_PORT); 178 outb(INPORT_MODE_BASE, INPORT_DATA_PORT);
175 179
176 input_register_device(&inport_dev); 180 input_register_device(inport_dev);
177
178 printk(KERN_INFO "input: " INPORT_NAME " at %#x irq %d\n", INPORT_BASE, inport_irq);
179 181
180 return 0; 182 return 0;
181} 183}
182 184
183static void __exit inport_exit(void) 185static void __exit inport_exit(void)
184{ 186{
185 input_unregister_device(&inport_dev); 187 input_unregister_device(inport_dev);
186 release_region(INPORT_BASE, INPORT_EXTENT); 188 release_region(INPORT_BASE, INPORT_EXTENT);
187} 189}
188 190
diff --git a/drivers/input/mouse/lifebook.c b/drivers/input/mouse/lifebook.c
index bd9df9b28325..55991424ac91 100644
--- a/drivers/input/mouse/lifebook.c
+++ b/drivers/input/mouse/lifebook.c
@@ -34,7 +34,7 @@ static struct dmi_system_id lifebook_dmi_table[] = {
34static psmouse_ret_t lifebook_process_byte(struct psmouse *psmouse, struct pt_regs *regs) 34static psmouse_ret_t lifebook_process_byte(struct psmouse *psmouse, struct pt_regs *regs)
35{ 35{
36 unsigned char *packet = psmouse->packet; 36 unsigned char *packet = psmouse->packet;
37 struct input_dev *dev = &psmouse->dev; 37 struct input_dev *dev = psmouse->dev;
38 38
39 if (psmouse->pktcnt != 3) 39 if (psmouse->pktcnt != 3)
40 return PSMOUSE_GOOD_DATA; 40 return PSMOUSE_GOOD_DATA;
@@ -113,15 +113,17 @@ int lifebook_detect(struct psmouse *psmouse, int set_properties)
113 113
114int lifebook_init(struct psmouse *psmouse) 114int lifebook_init(struct psmouse *psmouse)
115{ 115{
116 struct input_dev *input_dev = psmouse->dev;
117
116 if (lifebook_absolute_mode(psmouse)) 118 if (lifebook_absolute_mode(psmouse))
117 return -1; 119 return -1;
118 120
119 psmouse->dev.evbit[0] = BIT(EV_ABS) | BIT(EV_KEY) | BIT(EV_REL); 121 input_dev->evbit[0] = BIT(EV_ABS) | BIT(EV_KEY) | BIT(EV_REL);
120 psmouse->dev.keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT); 122 input_dev->keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
121 psmouse->dev.keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH); 123 input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
122 psmouse->dev.relbit[0] = BIT(REL_X) | BIT(REL_Y); 124 input_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y);
123 input_set_abs_params(&psmouse->dev, ABS_X, 0, 1024, 0, 0); 125 input_set_abs_params(input_dev, ABS_X, 0, 1024, 0, 0);
124 input_set_abs_params(&psmouse->dev, ABS_Y, 0, 1024, 0, 0); 126 input_set_abs_params(input_dev, ABS_Y, 0, 1024, 0, 0);
125 127
126 psmouse->protocol_handler = lifebook_process_byte; 128 psmouse->protocol_handler = lifebook_process_byte;
127 psmouse->set_resolution = lifebook_set_resolution; 129 psmouse->set_resolution = lifebook_set_resolution;
diff --git a/drivers/input/mouse/logibm.c b/drivers/input/mouse/logibm.c
index 8b5243167227..9c7ce38806d7 100644
--- a/drivers/input/mouse/logibm.c
+++ b/drivers/input/mouse/logibm.c
@@ -77,39 +77,7 @@ MODULE_PARM_DESC(irq, "IRQ number (5=default)");
77 77
78__obsolete_setup("logibm_irq="); 78__obsolete_setup("logibm_irq=");
79 79
80static irqreturn_t logibm_interrupt(int irq, void *dev_id, struct pt_regs *regs); 80static struct input_dev *logibm_dev;
81
82static int logibm_open(struct input_dev *dev)
83{
84 if (request_irq(logibm_irq, logibm_interrupt, 0, "logibm", NULL)) {
85 printk(KERN_ERR "logibm.c: Can't allocate irq %d\n", logibm_irq);
86 return -EBUSY;
87 }
88 outb(LOGIBM_ENABLE_IRQ, LOGIBM_CONTROL_PORT);
89 return 0;
90}
91
92static void logibm_close(struct input_dev *dev)
93{
94 outb(LOGIBM_DISABLE_IRQ, LOGIBM_CONTROL_PORT);
95 free_irq(logibm_irq, NULL);
96}
97
98static struct input_dev logibm_dev = {
99 .evbit = { BIT(EV_KEY) | BIT(EV_REL) },
100 .keybit = { [LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT) },
101 .relbit = { BIT(REL_X) | BIT(REL_Y) },
102 .open = logibm_open,
103 .close = logibm_close,
104 .name = "Logitech bus mouse",
105 .phys = "isa023c/input0",
106 .id = {
107 .bustype = BUS_ISA,
108 .vendor = 0x0003,
109 .product = 0x0001,
110 .version = 0x0100,
111 },
112};
113 81
114static irqreturn_t logibm_interrupt(int irq, void *dev_id, struct pt_regs *regs) 82static irqreturn_t logibm_interrupt(int irq, void *dev_id, struct pt_regs *regs)
115{ 83{
@@ -127,18 +95,34 @@ static irqreturn_t logibm_interrupt(int irq, void *dev_id, struct pt_regs *regs)
127 dy |= (buttons & 0xf) << 4; 95 dy |= (buttons & 0xf) << 4;
128 buttons = ~buttons >> 5; 96 buttons = ~buttons >> 5;
129 97
130 input_regs(&logibm_dev, regs); 98 input_regs(logibm_dev, regs);
131 input_report_rel(&logibm_dev, REL_X, dx); 99 input_report_rel(logibm_dev, REL_X, dx);
132 input_report_rel(&logibm_dev, REL_Y, dy); 100 input_report_rel(logibm_dev, REL_Y, dy);
133 input_report_key(&logibm_dev, BTN_RIGHT, buttons & 1); 101 input_report_key(logibm_dev, BTN_RIGHT, buttons & 1);
134 input_report_key(&logibm_dev, BTN_MIDDLE, buttons & 2); 102 input_report_key(logibm_dev, BTN_MIDDLE, buttons & 2);
135 input_report_key(&logibm_dev, BTN_LEFT, buttons & 4); 103 input_report_key(logibm_dev, BTN_LEFT, buttons & 4);
136 input_sync(&logibm_dev); 104 input_sync(logibm_dev);
137 105
138 outb(LOGIBM_ENABLE_IRQ, LOGIBM_CONTROL_PORT); 106 outb(LOGIBM_ENABLE_IRQ, LOGIBM_CONTROL_PORT);
139 return IRQ_HANDLED; 107 return IRQ_HANDLED;
140} 108}
141 109
110static int logibm_open(struct input_dev *dev)
111{
112 if (request_irq(logibm_irq, logibm_interrupt, 0, "logibm", NULL)) {
113 printk(KERN_ERR "logibm.c: Can't allocate irq %d\n", logibm_irq);
114 return -EBUSY;
115 }
116 outb(LOGIBM_ENABLE_IRQ, LOGIBM_CONTROL_PORT);
117 return 0;
118}
119
120static void logibm_close(struct input_dev *dev)
121{
122 outb(LOGIBM_DISABLE_IRQ, LOGIBM_CONTROL_PORT);
123 free_irq(logibm_irq, NULL);
124}
125
142static int __init logibm_init(void) 126static int __init logibm_init(void)
143{ 127{
144 if (!request_region(LOGIBM_BASE, LOGIBM_EXTENT, "logibm")) { 128 if (!request_region(LOGIBM_BASE, LOGIBM_EXTENT, "logibm")) {
@@ -159,16 +143,34 @@ static int __init logibm_init(void)
159 outb(LOGIBM_DEFAULT_MODE, LOGIBM_CONFIG_PORT); 143 outb(LOGIBM_DEFAULT_MODE, LOGIBM_CONFIG_PORT);
160 outb(LOGIBM_DISABLE_IRQ, LOGIBM_CONTROL_PORT); 144 outb(LOGIBM_DISABLE_IRQ, LOGIBM_CONTROL_PORT);
161 145
162 input_register_device(&logibm_dev); 146 if (!(logibm_dev = input_allocate_device())) {
147 printk(KERN_ERR "logibm.c: Not enough memory for input device\n");
148 release_region(LOGIBM_BASE, LOGIBM_EXTENT);
149 return -ENOMEM;
150 }
151
152 logibm_dev->name = "Logitech bus mouse";
153 logibm_dev->phys = "isa023c/input0";
154 logibm_dev->id.bustype = BUS_ISA;
155 logibm_dev->id.vendor = 0x0003;
156 logibm_dev->id.product = 0x0001;
157 logibm_dev->id.version = 0x0100;
158
159 logibm_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
160 logibm_dev->keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
161 logibm_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y);
162
163 logibm_dev->open = logibm_open;
164 logibm_dev->close = logibm_close;
163 165
164 printk(KERN_INFO "input: Logitech bus mouse at %#x irq %d\n", LOGIBM_BASE, logibm_irq); 166 input_register_device(logibm_dev);
165 167
166 return 0; 168 return 0;
167} 169}
168 170
169static void __exit logibm_exit(void) 171static void __exit logibm_exit(void)
170{ 172{
171 input_unregister_device(&logibm_dev); 173 input_unregister_device(logibm_dev);
172 release_region(LOGIBM_BASE, LOGIBM_EXTENT); 174 release_region(LOGIBM_BASE, LOGIBM_EXTENT);
173} 175}
174 176
diff --git a/drivers/input/mouse/logips2pp.c b/drivers/input/mouse/logips2pp.c
index 7df96525222e..0f69ff46c1ae 100644
--- a/drivers/input/mouse/logips2pp.c
+++ b/drivers/input/mouse/logips2pp.c
@@ -40,7 +40,7 @@ struct ps2pp_info {
40 40
41static psmouse_ret_t ps2pp_process_byte(struct psmouse *psmouse, struct pt_regs *regs) 41static psmouse_ret_t ps2pp_process_byte(struct psmouse *psmouse, struct pt_regs *regs)
42{ 42{
43 struct input_dev *dev = &psmouse->dev; 43 struct input_dev *dev = psmouse->dev;
44 unsigned char *packet = psmouse->packet; 44 unsigned char *packet = psmouse->packet;
45 45
46 if (psmouse->pktcnt < 3) 46 if (psmouse->pktcnt < 3)
@@ -257,25 +257,27 @@ static struct ps2pp_info *get_model_info(unsigned char model)
257static void ps2pp_set_model_properties(struct psmouse *psmouse, struct ps2pp_info *model_info, 257static void ps2pp_set_model_properties(struct psmouse *psmouse, struct ps2pp_info *model_info,
258 int using_ps2pp) 258 int using_ps2pp)
259{ 259{
260 struct input_dev *input_dev = psmouse->dev;
261
260 if (model_info->features & PS2PP_SIDE_BTN) 262 if (model_info->features & PS2PP_SIDE_BTN)
261 set_bit(BTN_SIDE, psmouse->dev.keybit); 263 set_bit(BTN_SIDE, input_dev->keybit);
262 264
263 if (model_info->features & PS2PP_EXTRA_BTN) 265 if (model_info->features & PS2PP_EXTRA_BTN)
264 set_bit(BTN_EXTRA, psmouse->dev.keybit); 266 set_bit(BTN_EXTRA, input_dev->keybit);
265 267
266 if (model_info->features & PS2PP_TASK_BTN) 268 if (model_info->features & PS2PP_TASK_BTN)
267 set_bit(BTN_TASK, psmouse->dev.keybit); 269 set_bit(BTN_TASK, input_dev->keybit);
268 270
269 if (model_info->features & PS2PP_NAV_BTN) { 271 if (model_info->features & PS2PP_NAV_BTN) {
270 set_bit(BTN_FORWARD, psmouse->dev.keybit); 272 set_bit(BTN_FORWARD, input_dev->keybit);
271 set_bit(BTN_BACK, psmouse->dev.keybit); 273 set_bit(BTN_BACK, input_dev->keybit);
272 } 274 }
273 275
274 if (model_info->features & PS2PP_WHEEL) 276 if (model_info->features & PS2PP_WHEEL)
275 set_bit(REL_WHEEL, psmouse->dev.relbit); 277 set_bit(REL_WHEEL, input_dev->relbit);
276 278
277 if (model_info->features & PS2PP_HWHEEL) 279 if (model_info->features & PS2PP_HWHEEL)
278 set_bit(REL_HWHEEL, psmouse->dev.relbit); 280 set_bit(REL_HWHEEL, input_dev->relbit);
279 281
280 switch (model_info->kind) { 282 switch (model_info->kind) {
281 case PS2PP_KIND_WHEEL: 283 case PS2PP_KIND_WHEEL:
@@ -387,7 +389,7 @@ int ps2pp_init(struct psmouse *psmouse, int set_properties)
387 } 389 }
388 390
389 if (buttons < 3) 391 if (buttons < 3)
390 clear_bit(BTN_MIDDLE, psmouse->dev.keybit); 392 clear_bit(BTN_MIDDLE, psmouse->dev->keybit);
391 393
392 if (model_info) 394 if (model_info)
393 ps2pp_set_model_properties(psmouse, model_info, use_ps2pp); 395 ps2pp_set_model_properties(psmouse, model_info, use_ps2pp);
diff --git a/drivers/input/mouse/maplemouse.c b/drivers/input/mouse/maplemouse.c
index e90c60cbbf05..b5b34fe4fee8 100644
--- a/drivers/input/mouse/maplemouse.c
+++ b/drivers/input/mouse/maplemouse.c
@@ -41,13 +41,12 @@ static int dc_mouse_connect(struct maple_device *dev)
41 unsigned long data = be32_to_cpu(dev->devinfo.function_data[0]); 41 unsigned long data = be32_to_cpu(dev->devinfo.function_data[0]);
42 struct input_dev *input_dev; 42 struct input_dev *input_dev;
43 43
44 if (!(input_dev = kmalloc(sizeof(struct input_dev), GFP_KERNEL))) 44 dev->private_data = input_dev = input_allocate_device();
45 return -1; 45 if (!input_dev)
46 return -ENOMEM;
46 47
47 dev->private_data = input_dev; 48 dev->private_data = input_dev;
48 49
49 memset(input_dev, 0, sizeof(struct dc_mouse));
50 init_input_dev(input_dev);
51 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL); 50 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
52 input_dev->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE); 51 input_dev->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE);
53 input_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y) | BIT(REL_WHEEL); 52 input_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y) | BIT(REL_WHEEL);
@@ -59,8 +58,6 @@ static int dc_mouse_connect(struct maple_device *dev)
59 58
60 maple_getcond_callback(dev, dc_mouse_callback, 1, MAPLE_FUNC_MOUSE); 59 maple_getcond_callback(dev, dc_mouse_callback, 1, MAPLE_FUNC_MOUSE);
61 60
62 printk(KERN_INFO "input: mouse(0x%lx): %s\n", data, input_dev->name);
63
64 return 0; 61 return 0;
65} 62}
66 63
@@ -70,7 +67,6 @@ static void dc_mouse_disconnect(struct maple_device *dev)
70 struct input_dev *input_dev = dev->private_data; 67 struct input_dev *input_dev = dev->private_data;
71 68
72 input_unregister_device(input_dev); 69 input_unregister_device(input_dev);
73 kfree(input_dev);
74} 70}
75 71
76 72
diff --git a/drivers/input/mouse/pc110pad.c b/drivers/input/mouse/pc110pad.c
index 93393d5c0078..d284ea712151 100644
--- a/drivers/input/mouse/pc110pad.c
+++ b/drivers/input/mouse/pc110pad.c
@@ -53,13 +53,10 @@ MODULE_LICENSE("GPL");
53static int pc110pad_irq = 10; 53static int pc110pad_irq = 10;
54static int pc110pad_io = 0x15e0; 54static int pc110pad_io = 0x15e0;
55 55
56static struct input_dev pc110pad_dev; 56static struct input_dev *pc110pad_dev;
57static int pc110pad_data[3]; 57static int pc110pad_data[3];
58static int pc110pad_count; 58static int pc110pad_count;
59 59
60static char *pc110pad_name = "IBM PC110 TouchPad";
61static char *pc110pad_phys = "isa15e0/input0";
62
63static irqreturn_t pc110pad_interrupt(int irq, void *ptr, struct pt_regs *regs) 60static irqreturn_t pc110pad_interrupt(int irq, void *ptr, struct pt_regs *regs)
64{ 61{
65 int value = inb_p(pc110pad_io); 62 int value = inb_p(pc110pad_io);
@@ -74,14 +71,14 @@ static irqreturn_t pc110pad_interrupt(int irq, void *ptr, struct pt_regs *regs)
74 if (pc110pad_count < 3) 71 if (pc110pad_count < 3)
75 return IRQ_HANDLED; 72 return IRQ_HANDLED;
76 73
77 input_regs(&pc110pad_dev, regs); 74 input_regs(pc110pad_dev, regs);
78 input_report_key(&pc110pad_dev, BTN_TOUCH, 75 input_report_key(pc110pad_dev, BTN_TOUCH,
79 pc110pad_data[0] & 0x01); 76 pc110pad_data[0] & 0x01);
80 input_report_abs(&pc110pad_dev, ABS_X, 77 input_report_abs(pc110pad_dev, ABS_X,
81 pc110pad_data[1] | ((pc110pad_data[0] << 3) & 0x80) | ((pc110pad_data[0] << 1) & 0x100)); 78 pc110pad_data[1] | ((pc110pad_data[0] << 3) & 0x80) | ((pc110pad_data[0] << 1) & 0x100));
82 input_report_abs(&pc110pad_dev, ABS_Y, 79 input_report_abs(pc110pad_dev, ABS_Y,
83 pc110pad_data[2] | ((pc110pad_data[0] << 4) & 0x80)); 80 pc110pad_data[2] | ((pc110pad_data[0] << 4) & 0x80));
84 input_sync(&pc110pad_dev); 81 input_sync(pc110pad_dev);
85 82
86 pc110pad_count = 0; 83 pc110pad_count = 0;
87 return IRQ_HANDLED; 84 return IRQ_HANDLED;
@@ -94,9 +91,9 @@ static void pc110pad_close(struct input_dev *dev)
94 91
95static int pc110pad_open(struct input_dev *dev) 92static int pc110pad_open(struct input_dev *dev)
96{ 93{
97 pc110pad_interrupt(0,NULL,NULL); 94 pc110pad_interrupt(0, NULL, NULL);
98 pc110pad_interrupt(0,NULL,NULL); 95 pc110pad_interrupt(0, NULL, NULL);
99 pc110pad_interrupt(0,NULL,NULL); 96 pc110pad_interrupt(0, NULL, NULL);
100 outb(PC110PAD_ON, pc110pad_io + 2); 97 outb(PC110PAD_ON, pc110pad_io + 2);
101 pc110pad_count = 0; 98 pc110pad_count = 0;
102 99
@@ -127,45 +124,46 @@ static int __init pc110pad_init(void)
127 124
128 outb(PC110PAD_OFF, pc110pad_io + 2); 125 outb(PC110PAD_OFF, pc110pad_io + 2);
129 126
130 if (request_irq(pc110pad_irq, pc110pad_interrupt, 0, "pc110pad", NULL)) 127 if (request_irq(pc110pad_irq, pc110pad_interrupt, 0, "pc110pad", NULL)) {
131 {
132 release_region(pc110pad_io, 4); 128 release_region(pc110pad_io, 4);
133 printk(KERN_ERR "pc110pad: Unable to get irq %d.\n", pc110pad_irq); 129 printk(KERN_ERR "pc110pad: Unable to get irq %d.\n", pc110pad_irq);
134 return -EBUSY; 130 return -EBUSY;
135 } 131 }
136 132
137 pc110pad_dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 133 if (!(pc110pad_dev = input_allocate_device())) {
138 pc110pad_dev.absbit[0] = BIT(ABS_X) | BIT(ABS_Y); 134 free_irq(pc110pad_irq, NULL);
139 pc110pad_dev.keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH); 135 release_region(pc110pad_io, 4);
136 printk(KERN_ERR "pc110pad: Not enough memory.\n");
137 return -ENOMEM;
138 }
140 139
141 pc110pad_dev.absmax[ABS_X] = 0x1ff; 140 pc110pad_dev->name = "IBM PC110 TouchPad";
142 pc110pad_dev.absmax[ABS_Y] = 0x0ff; 141 pc110pad_dev->phys = "isa15e0/input0";
142 pc110pad_dev->id.bustype = BUS_ISA;
143 pc110pad_dev->id.vendor = 0x0003;
144 pc110pad_dev->id.product = 0x0001;
145 pc110pad_dev->id.version = 0x0100;
143 146
144 pc110pad_dev.open = pc110pad_open; 147 pc110pad_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
145 pc110pad_dev.close = pc110pad_close; 148 pc110pad_dev->absbit[0] = BIT(ABS_X) | BIT(ABS_Y);
149 pc110pad_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
146 150
147 pc110pad_dev.name = pc110pad_name; 151 pc110pad_dev->absmax[ABS_X] = 0x1ff;
148 pc110pad_dev.phys = pc110pad_phys; 152 pc110pad_dev->absmax[ABS_Y] = 0x0ff;
149 pc110pad_dev.id.bustype = BUS_ISA;
150 pc110pad_dev.id.vendor = 0x0003;
151 pc110pad_dev.id.product = 0x0001;
152 pc110pad_dev.id.version = 0x0100;
153 153
154 input_register_device(&pc110pad_dev); 154 pc110pad_dev->open = pc110pad_open;
155 pc110pad_dev->close = pc110pad_close;
155 156
156 printk(KERN_INFO "input: %s at %#x irq %d\n", 157 input_register_device(pc110pad_dev);
157 pc110pad_name, pc110pad_io, pc110pad_irq);
158 158
159 return 0; 159 return 0;
160} 160}
161 161
162static void __exit pc110pad_exit(void) 162static void __exit pc110pad_exit(void)
163{ 163{
164 input_unregister_device(&pc110pad_dev);
165
166 outb(PC110PAD_OFF, pc110pad_io + 2); 164 outb(PC110PAD_OFF, pc110pad_io + 2);
167
168 free_irq(pc110pad_irq, NULL); 165 free_irq(pc110pad_irq, NULL);
166 input_unregister_device(pc110pad_dev);
169 release_region(pc110pad_io, 4); 167 release_region(pc110pad_io, 4);
170} 168}
171 169
diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
index af24313ff5bb..6ee9999a2eaa 100644
--- a/drivers/input/mouse/psmouse-base.c
+++ b/drivers/input/mouse/psmouse-base.c
@@ -114,7 +114,7 @@ struct psmouse_protocol {
114 114
115static psmouse_ret_t psmouse_process_byte(struct psmouse *psmouse, struct pt_regs *regs) 115static psmouse_ret_t psmouse_process_byte(struct psmouse *psmouse, struct pt_regs *regs)
116{ 116{
117 struct input_dev *dev = &psmouse->dev; 117 struct input_dev *dev = psmouse->dev;
118 unsigned char *packet = psmouse->packet; 118 unsigned char *packet = psmouse->packet;
119 119
120 if (psmouse->pktcnt < psmouse->pktsize) 120 if (psmouse->pktcnt < psmouse->pktsize)
@@ -333,12 +333,11 @@ static int genius_detect(struct psmouse *psmouse, int set_properties)
333 return -1; 333 return -1;
334 334
335 if (set_properties) { 335 if (set_properties) {
336 set_bit(BTN_EXTRA, psmouse->dev.keybit); 336 set_bit(BTN_EXTRA, psmouse->dev->keybit);
337 set_bit(BTN_SIDE, psmouse->dev.keybit); 337 set_bit(BTN_SIDE, psmouse->dev->keybit);
338 set_bit(REL_WHEEL, psmouse->dev.relbit); 338 set_bit(REL_WHEEL, psmouse->dev->relbit);
339 339
340 psmouse->vendor = "Genius"; 340 psmouse->vendor = "Genius";
341 psmouse->name = "Wheel Mouse";
342 psmouse->pktsize = 4; 341 psmouse->pktsize = 4;
343 } 342 }
344 343
@@ -365,8 +364,8 @@ static int intellimouse_detect(struct psmouse *psmouse, int set_properties)
365 return -1; 364 return -1;
366 365
367 if (set_properties) { 366 if (set_properties) {
368 set_bit(BTN_MIDDLE, psmouse->dev.keybit); 367 set_bit(BTN_MIDDLE, psmouse->dev->keybit);
369 set_bit(REL_WHEEL, psmouse->dev.relbit); 368 set_bit(REL_WHEEL, psmouse->dev->relbit);
370 369
371 if (!psmouse->vendor) psmouse->vendor = "Generic"; 370 if (!psmouse->vendor) psmouse->vendor = "Generic";
372 if (!psmouse->name) psmouse->name = "Wheel Mouse"; 371 if (!psmouse->name) psmouse->name = "Wheel Mouse";
@@ -398,10 +397,10 @@ static int im_explorer_detect(struct psmouse *psmouse, int set_properties)
398 return -1; 397 return -1;
399 398
400 if (set_properties) { 399 if (set_properties) {
401 set_bit(BTN_MIDDLE, psmouse->dev.keybit); 400 set_bit(BTN_MIDDLE, psmouse->dev->keybit);
402 set_bit(REL_WHEEL, psmouse->dev.relbit); 401 set_bit(REL_WHEEL, psmouse->dev->relbit);
403 set_bit(BTN_SIDE, psmouse->dev.keybit); 402 set_bit(BTN_SIDE, psmouse->dev->keybit);
404 set_bit(BTN_EXTRA, psmouse->dev.keybit); 403 set_bit(BTN_EXTRA, psmouse->dev->keybit);
405 404
406 if (!psmouse->vendor) psmouse->vendor = "Generic"; 405 if (!psmouse->vendor) psmouse->vendor = "Generic";
407 if (!psmouse->name) psmouse->name = "Explorer Mouse"; 406 if (!psmouse->name) psmouse->name = "Explorer Mouse";
@@ -433,7 +432,7 @@ static int thinking_detect(struct psmouse *psmouse, int set_properties)
433 return -1; 432 return -1;
434 433
435 if (set_properties) { 434 if (set_properties) {
436 set_bit(BTN_EXTRA, psmouse->dev.keybit); 435 set_bit(BTN_EXTRA, psmouse->dev->keybit);
437 436
438 psmouse->vendor = "Kensington"; 437 psmouse->vendor = "Kensington";
439 psmouse->name = "ThinkingMouse"; 438 psmouse->name = "ThinkingMouse";
@@ -839,9 +838,9 @@ static void psmouse_disconnect(struct serio *serio)
839 838
840 psmouse_set_state(psmouse, PSMOUSE_IGNORE); 839 psmouse_set_state(psmouse, PSMOUSE_IGNORE);
841 840
842 input_unregister_device(&psmouse->dev);
843 serio_close(serio); 841 serio_close(serio);
844 serio_set_drvdata(serio, NULL); 842 serio_set_drvdata(serio, NULL);
843 input_unregister_device(psmouse->dev);
845 kfree(psmouse); 844 kfree(psmouse);
846 845
847 if (parent) 846 if (parent)
@@ -852,16 +851,14 @@ static void psmouse_disconnect(struct serio *serio)
852 851
853static int psmouse_switch_protocol(struct psmouse *psmouse, struct psmouse_protocol *proto) 852static int psmouse_switch_protocol(struct psmouse *psmouse, struct psmouse_protocol *proto)
854{ 853{
855 memset(&psmouse->dev, 0, sizeof(struct input_dev)); 854 struct input_dev *input_dev = psmouse->dev;
856 855
857 init_input_dev(&psmouse->dev); 856 input_dev->private = psmouse;
857 input_dev->cdev.dev = &psmouse->ps2dev.serio->dev;
858 858
859 psmouse->dev.private = psmouse; 859 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
860 psmouse->dev.dev = &psmouse->ps2dev.serio->dev; 860 input_dev->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
861 861 input_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y);
862 psmouse->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
863 psmouse->dev.keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
864 psmouse->dev.relbit[0] = BIT(REL_X) | BIT(REL_Y);
865 862
866 psmouse->set_rate = psmouse_set_rate; 863 psmouse->set_rate = psmouse_set_rate;
867 psmouse->set_resolution = psmouse_set_resolution; 864 psmouse->set_resolution = psmouse_set_resolution;
@@ -883,12 +880,12 @@ static int psmouse_switch_protocol(struct psmouse *psmouse, struct psmouse_proto
883 sprintf(psmouse->devname, "%s %s %s", 880 sprintf(psmouse->devname, "%s %s %s",
884 psmouse_protocol_by_type(psmouse->type)->name, psmouse->vendor, psmouse->name); 881 psmouse_protocol_by_type(psmouse->type)->name, psmouse->vendor, psmouse->name);
885 882
886 psmouse->dev.name = psmouse->devname; 883 input_dev->name = psmouse->devname;
887 psmouse->dev.phys = psmouse->phys; 884 input_dev->phys = psmouse->phys;
888 psmouse->dev.id.bustype = BUS_I8042; 885 input_dev->id.bustype = BUS_I8042;
889 psmouse->dev.id.vendor = 0x0002; 886 input_dev->id.vendor = 0x0002;
890 psmouse->dev.id.product = psmouse->type; 887 input_dev->id.product = psmouse->type;
891 psmouse->dev.id.version = psmouse->model; 888 input_dev->id.version = psmouse->model;
892 889
893 return 0; 890 return 0;
894} 891}
@@ -900,7 +897,8 @@ static int psmouse_switch_protocol(struct psmouse *psmouse, struct psmouse_proto
900static int psmouse_connect(struct serio *serio, struct serio_driver *drv) 897static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
901{ 898{
902 struct psmouse *psmouse, *parent = NULL; 899 struct psmouse *psmouse, *parent = NULL;
903 int retval; 900 struct input_dev *input_dev;
901 int retval = -ENOMEM;
904 902
905 down(&psmouse_sem); 903 down(&psmouse_sem);
906 904
@@ -913,12 +911,13 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
913 psmouse_deactivate(parent); 911 psmouse_deactivate(parent);
914 } 912 }
915 913
916 if (!(psmouse = kzalloc(sizeof(struct psmouse), GFP_KERNEL))) { 914 psmouse = kzalloc(sizeof(struct psmouse), GFP_KERNEL);
917 retval = -ENOMEM; 915 input_dev = input_allocate_device();
916 if (!psmouse || !input_dev)
918 goto out; 917 goto out;
919 }
920 918
921 ps2_init(&psmouse->ps2dev, serio); 919 ps2_init(&psmouse->ps2dev, serio);
920 psmouse->dev = input_dev;
922 sprintf(psmouse->phys, "%s/input0", serio->phys); 921 sprintf(psmouse->phys, "%s/input0", serio->phys);
923 922
924 psmouse_set_state(psmouse, PSMOUSE_INITIALIZING); 923 psmouse_set_state(psmouse, PSMOUSE_INITIALIZING);
@@ -926,16 +925,11 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
926 serio_set_drvdata(serio, psmouse); 925 serio_set_drvdata(serio, psmouse);
927 926
928 retval = serio_open(serio, drv); 927 retval = serio_open(serio, drv);
929 if (retval) { 928 if (retval)
930 serio_set_drvdata(serio, NULL);
931 kfree(psmouse);
932 goto out; 929 goto out;
933 }
934 930
935 if (psmouse_probe(psmouse) < 0) { 931 if (psmouse_probe(psmouse) < 0) {
936 serio_close(serio); 932 serio_close(serio);
937 serio_set_drvdata(serio, NULL);
938 kfree(psmouse);
939 retval = -ENODEV; 933 retval = -ENODEV;
940 goto out; 934 goto out;
941 } 935 }
@@ -947,13 +941,11 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
947 941
948 psmouse_switch_protocol(psmouse, NULL); 942 psmouse_switch_protocol(psmouse, NULL);
949 943
950 input_register_device(&psmouse->dev);
951 printk(KERN_INFO "input: %s on %s\n", psmouse->devname, serio->phys);
952
953 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE); 944 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
954
955 psmouse_initialize(psmouse); 945 psmouse_initialize(psmouse);
956 946
947 input_register_device(psmouse->dev);
948
957 if (parent && parent->pt_activate) 949 if (parent && parent->pt_activate)
958 parent->pt_activate(parent); 950 parent->pt_activate(parent);
959 951
@@ -964,6 +956,12 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
964 retval = 0; 956 retval = 0;
965 957
966out: 958out:
959 if (retval) {
960 serio_set_drvdata(serio, NULL);
961 input_free_device(input_dev);
962 kfree(psmouse);
963 }
964
967 /* If this is a pass-through port the parent needs to be re-activated */ 965 /* If this is a pass-through port the parent needs to be re-activated */
968 if (parent) 966 if (parent)
969 psmouse_activate(parent); 967 psmouse_activate(parent);
@@ -1161,6 +1159,7 @@ static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, void *data, co
1161{ 1159{
1162 struct serio *serio = psmouse->ps2dev.serio; 1160 struct serio *serio = psmouse->ps2dev.serio;
1163 struct psmouse *parent = NULL; 1161 struct psmouse *parent = NULL;
1162 struct input_dev *new_dev;
1164 struct psmouse_protocol *proto; 1163 struct psmouse_protocol *proto;
1165 int retry = 0; 1164 int retry = 0;
1166 1165
@@ -1170,9 +1169,13 @@ static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, void *data, co
1170 if (psmouse->type == proto->type) 1169 if (psmouse->type == proto->type)
1171 return count; 1170 return count;
1172 1171
1172 if (!(new_dev = input_allocate_device()))
1173 return -ENOMEM;
1174
1173 while (serio->child) { 1175 while (serio->child) {
1174 if (++retry > 3) { 1176 if (++retry > 3) {
1175 printk(KERN_WARNING "psmouse: failed to destroy child port, protocol change aborted.\n"); 1177 printk(KERN_WARNING "psmouse: failed to destroy child port, protocol change aborted.\n");
1178 input_free_device(new_dev);
1176 return -EIO; 1179 return -EIO;
1177 } 1180 }
1178 1181
@@ -1182,11 +1185,15 @@ static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, void *data, co
1182 serio_pin_driver_uninterruptible(serio); 1185 serio_pin_driver_uninterruptible(serio);
1183 down(&psmouse_sem); 1186 down(&psmouse_sem);
1184 1187
1185 if (serio->drv != &psmouse_drv) 1188 if (serio->drv != &psmouse_drv) {
1189 input_free_device(new_dev);
1186 return -ENODEV; 1190 return -ENODEV;
1191 }
1187 1192
1188 if (psmouse->type == proto->type) 1193 if (psmouse->type == proto->type) {
1194 input_free_device(new_dev);
1189 return count; /* switched by other thread */ 1195 return count; /* switched by other thread */
1196 }
1190 } 1197 }
1191 1198
1192 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) { 1199 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
@@ -1199,8 +1206,9 @@ static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, void *data, co
1199 psmouse->disconnect(psmouse); 1206 psmouse->disconnect(psmouse);
1200 1207
1201 psmouse_set_state(psmouse, PSMOUSE_IGNORE); 1208 psmouse_set_state(psmouse, PSMOUSE_IGNORE);
1202 input_unregister_device(&psmouse->dev); 1209 input_unregister_device(psmouse->dev);
1203 1210
1211 psmouse->dev = new_dev;
1204 psmouse_set_state(psmouse, PSMOUSE_INITIALIZING); 1212 psmouse_set_state(psmouse, PSMOUSE_INITIALIZING);
1205 1213
1206 if (psmouse_switch_protocol(psmouse, proto) < 0) { 1214 if (psmouse_switch_protocol(psmouse, proto) < 0) {
@@ -1212,8 +1220,7 @@ static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, void *data, co
1212 psmouse_initialize(psmouse); 1220 psmouse_initialize(psmouse);
1213 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE); 1221 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
1214 1222
1215 input_register_device(&psmouse->dev); 1223 input_register_device(psmouse->dev);
1216 printk(KERN_INFO "input: %s on %s\n", psmouse->devname, serio->phys);
1217 1224
1218 if (parent && parent->pt_activate) 1225 if (parent && parent->pt_activate)
1219 parent->pt_activate(parent); 1226 parent->pt_activate(parent);
diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
index 45d2bd774f00..7c4192bd1279 100644
--- a/drivers/input/mouse/psmouse.h
+++ b/drivers/input/mouse/psmouse.h
@@ -36,7 +36,7 @@ typedef enum {
36 36
37struct psmouse { 37struct psmouse {
38 void *private; 38 void *private;
39 struct input_dev dev; 39 struct input_dev *dev;
40 struct ps2dev ps2dev; 40 struct ps2dev ps2dev;
41 char *vendor; 41 char *vendor;
42 char *name; 42 char *name;
diff --git a/drivers/input/mouse/rpcmouse.c b/drivers/input/mouse/rpcmouse.c
index 8fe1212b8fd7..09b6ffdb7582 100644
--- a/drivers/input/mouse/rpcmouse.c
+++ b/drivers/input/mouse/rpcmouse.c
@@ -34,20 +34,7 @@ MODULE_DESCRIPTION("Acorn RiscPC mouse driver");
34MODULE_LICENSE("GPL"); 34MODULE_LICENSE("GPL");
35 35
36static short rpcmouse_lastx, rpcmouse_lasty; 36static short rpcmouse_lastx, rpcmouse_lasty;
37 37static struct input_dev *rpcmouse_dev;
38static struct input_dev rpcmouse_dev = {
39 .evbit = { BIT(EV_KEY) | BIT(EV_REL) },
40 .keybit = { [LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT) },
41 .relbit = { BIT(REL_X) | BIT(REL_Y) },
42 .name = "Acorn RiscPC Mouse",
43 .phys = "rpcmouse/input0",
44 .id = {
45 .bustype = BUS_HOST,
46 .vendor = 0x0005,
47 .product = 0x0001,
48 .version = 0x0100,
49 },
50};
51 38
52static irqreturn_t rpcmouse_irq(int irq, void *dev_id, struct pt_regs *regs) 39static irqreturn_t rpcmouse_irq(int irq, void *dev_id, struct pt_regs *regs)
53{ 40{
@@ -78,29 +65,41 @@ static irqreturn_t rpcmouse_irq(int irq, void *dev_id, struct pt_regs *regs)
78 return IRQ_HANDLED; 65 return IRQ_HANDLED;
79} 66}
80 67
68
81static int __init rpcmouse_init(void) 69static int __init rpcmouse_init(void)
82{ 70{
83 init_input_dev(&rpcmouse_dev); 71 if (!(rpcmouse_dev = input_allocate_device()))
72 return -ENOMEM;
73
74 rpcmouse_dev->name = "Acorn RiscPC Mouse";
75 rpcmouse_dev->phys = "rpcmouse/input0";
76 rpcmouse_dev->id.bustype = BUS_HOST;
77 rpcmouse_dev->id.vendor = 0x0005;
78 rpcmouse_dev->id.product = 0x0001;
79 rpcmouse_dev->id.version = 0x0100;
80
81 rpcmouse_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
82 rpcmouse_dev->keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
83 rpcmouse_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y);
84 84
85 rpcmouse_lastx = (short) iomd_readl(IOMD_MOUSEX); 85 rpcmouse_lastx = (short) iomd_readl(IOMD_MOUSEX);
86 rpcmouse_lasty = (short) iomd_readl(IOMD_MOUSEY); 86 rpcmouse_lasty = (short) iomd_readl(IOMD_MOUSEY);
87 87
88 if (request_irq(IRQ_VSYNCPULSE, rpcmouse_irq, SA_SHIRQ, "rpcmouse", &rpcmouse_dev)) { 88 if (request_irq(IRQ_VSYNCPULSE, rpcmouse_irq, SA_SHIRQ, "rpcmouse", rpcmouse_dev)) {
89 printk(KERN_ERR "rpcmouse: unable to allocate VSYNC interrupt\n"); 89 printk(KERN_ERR "rpcmouse: unable to allocate VSYNC interrupt\n");
90 return -1; 90 input_free_device(rpcmouse_dev);
91 return -EBUSY;
91 } 92 }
92 93
93 input_register_device(&rpcmouse_dev); 94 input_register_device(rpcmouse_dev);
94
95 printk(KERN_INFO "input: Acorn RiscPC mouse\n");
96 95
97 return 0; 96 return 0;
98} 97}
99 98
100static void __exit rpcmouse_exit(void) 99static void __exit rpcmouse_exit(void)
101{ 100{
102 input_unregister_device(&rpcmouse_dev); 101 free_irq(IRQ_VSYNCPULSE, rpcmouse_dev);
103 free_irq(IRQ_VSYNCPULSE, &rpcmouse_dev); 102 input_unregister_device(rpcmouse_dev);
104} 103}
105 104
106module_init(rpcmouse_init); 105module_init(rpcmouse_init);
diff --git a/drivers/input/mouse/sermouse.c b/drivers/input/mouse/sermouse.c
index d12b93ae3900..4bf584364d28 100644
--- a/drivers/input/mouse/sermouse.c
+++ b/drivers/input/mouse/sermouse.c
@@ -48,7 +48,7 @@ static char *sermouse_protocols[] = { "None", "Mouse Systems Mouse", "Sun Mouse"
48 "Logitech MZ++ Mouse"}; 48 "Logitech MZ++ Mouse"};
49 49
50struct sermouse { 50struct sermouse {
51 struct input_dev dev; 51 struct input_dev *dev;
52 signed char buf[8]; 52 signed char buf[8];
53 unsigned char count; 53 unsigned char count;
54 unsigned char type; 54 unsigned char type;
@@ -64,7 +64,7 @@ struct sermouse {
64 64
65static void sermouse_process_msc(struct sermouse *sermouse, signed char data, struct pt_regs *regs) 65static void sermouse_process_msc(struct sermouse *sermouse, signed char data, struct pt_regs *regs)
66{ 66{
67 struct input_dev *dev = &sermouse->dev; 67 struct input_dev *dev = sermouse->dev;
68 signed char *buf = sermouse->buf; 68 signed char *buf = sermouse->buf;
69 69
70 input_regs(dev, regs); 70 input_regs(dev, regs);
@@ -107,7 +107,7 @@ static void sermouse_process_msc(struct sermouse *sermouse, signed char data, st
107 107
108static void sermouse_process_ms(struct sermouse *sermouse, signed char data, struct pt_regs *regs) 108static void sermouse_process_ms(struct sermouse *sermouse, signed char data, struct pt_regs *regs)
109{ 109{
110 struct input_dev *dev = &sermouse->dev; 110 struct input_dev *dev = sermouse->dev;
111 signed char *buf = sermouse->buf; 111 signed char *buf = sermouse->buf;
112 112
113 if (data & 0x40) sermouse->count = 0; 113 if (data & 0x40) sermouse->count = 0;
@@ -230,9 +230,9 @@ static void sermouse_disconnect(struct serio *serio)
230{ 230{
231 struct sermouse *sermouse = serio_get_drvdata(serio); 231 struct sermouse *sermouse = serio_get_drvdata(serio);
232 232
233 input_unregister_device(&sermouse->dev);
234 serio_close(serio); 233 serio_close(serio);
235 serio_set_drvdata(serio, NULL); 234 serio_set_drvdata(serio, NULL);
235 input_unregister_device(sermouse->dev);
236 kfree(sermouse); 236 kfree(sermouse);
237} 237}
238 238
@@ -244,56 +244,52 @@ static void sermouse_disconnect(struct serio *serio)
244static int sermouse_connect(struct serio *serio, struct serio_driver *drv) 244static int sermouse_connect(struct serio *serio, struct serio_driver *drv)
245{ 245{
246 struct sermouse *sermouse; 246 struct sermouse *sermouse;
247 unsigned char c; 247 struct input_dev *input_dev;
248 int err; 248 unsigned char c = serio->id.extra;
249 int err = -ENOMEM;
249 250
250 if (!serio->id.proto || serio->id.proto > SERIO_MZPP) 251 sermouse = kzalloc(sizeof(struct sermouse), GFP_KERNEL);
251 return -ENODEV; 252 input_dev = input_allocate_device();
252 253 if (!sermouse || !input_dev)
253 if (!(sermouse = kmalloc(sizeof(struct sermouse), GFP_KERNEL))) 254 goto fail;
254 return -ENOMEM;
255
256 memset(sermouse, 0, sizeof(struct sermouse));
257
258 init_input_dev(&sermouse->dev);
259 sermouse->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
260 sermouse->dev.keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT);
261 sermouse->dev.relbit[0] = BIT(REL_X) | BIT(REL_Y);
262 sermouse->dev.private = sermouse;
263
264 sermouse->type = serio->id.proto;
265 c = serio->id.extra;
266
267 if (c & 0x01) set_bit(BTN_MIDDLE, sermouse->dev.keybit);
268 if (c & 0x02) set_bit(BTN_SIDE, sermouse->dev.keybit);
269 if (c & 0x04) set_bit(BTN_EXTRA, sermouse->dev.keybit);
270 if (c & 0x10) set_bit(REL_WHEEL, sermouse->dev.relbit);
271 if (c & 0x20) set_bit(REL_HWHEEL, sermouse->dev.relbit);
272 255
256 sermouse->dev = input_dev;
273 sprintf(sermouse->phys, "%s/input0", serio->phys); 257 sprintf(sermouse->phys, "%s/input0", serio->phys);
258 sermouse->type = serio->id.proto;
274 259
275 sermouse->dev.name = sermouse_protocols[sermouse->type]; 260 input_dev->name = sermouse_protocols[sermouse->type];
276 sermouse->dev.phys = sermouse->phys; 261 input_dev->phys = sermouse->phys;
277 sermouse->dev.id.bustype = BUS_RS232; 262 input_dev->id.bustype = BUS_RS232;
278 sermouse->dev.id.vendor = sermouse->type; 263 input_dev->id.vendor = sermouse->type;
279 sermouse->dev.id.product = c; 264 input_dev->id.product = c;
280 sermouse->dev.id.version = 0x0100; 265 input_dev->id.version = 0x0100;
281 sermouse->dev.dev = &serio->dev; 266 input_dev->cdev.dev = &serio->dev;
267
268 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
269 input_dev->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT);
270 input_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y);
271 input_dev->private = sermouse;
272
273 if (c & 0x01) set_bit(BTN_MIDDLE, input_dev->keybit);
274 if (c & 0x02) set_bit(BTN_SIDE, input_dev->keybit);
275 if (c & 0x04) set_bit(BTN_EXTRA, input_dev->keybit);
276 if (c & 0x10) set_bit(REL_WHEEL, input_dev->relbit);
277 if (c & 0x20) set_bit(REL_HWHEEL, input_dev->relbit);
282 278
283 serio_set_drvdata(serio, sermouse); 279 serio_set_drvdata(serio, sermouse);
284 280
285 err = serio_open(serio, drv); 281 err = serio_open(serio, drv);
286 if (err) { 282 if (err)
287 serio_set_drvdata(serio, NULL); 283 goto fail;
288 kfree(sermouse);
289 return err;
290 }
291
292 input_register_device(&sermouse->dev);
293 284
294 printk(KERN_INFO "input: %s on %s\n", sermouse_protocols[sermouse->type], serio->phys); 285 input_register_device(sermouse->dev);
295 286
296 return 0; 287 return 0;
288
289 fail: serio_set_drvdata(serio, NULL);
290 input_free_device(input_dev);
291 kfree(sermouse);
292 return err;
297} 293}
298 294
299static struct serio_device_id sermouse_serio_ids[] = { 295static struct serio_device_id sermouse_serio_ids[] = {
diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c
index 029309422409..97cdfd6acaca 100644
--- a/drivers/input/mouse/synaptics.c
+++ b/drivers/input/mouse/synaptics.c
@@ -342,7 +342,7 @@ static void synaptics_parse_hw_state(unsigned char buf[], struct synaptics_data
342 */ 342 */
343static void synaptics_process_packet(struct psmouse *psmouse) 343static void synaptics_process_packet(struct psmouse *psmouse)
344{ 344{
345 struct input_dev *dev = &psmouse->dev; 345 struct input_dev *dev = psmouse->dev;
346 struct synaptics_data *priv = psmouse->private; 346 struct synaptics_data *priv = psmouse->private;
347 struct synaptics_hw_state hw; 347 struct synaptics_hw_state hw;
348 int num_fingers; 348 int num_fingers;
@@ -473,7 +473,7 @@ static unsigned char synaptics_detect_pkt_type(struct psmouse *psmouse)
473 473
474static psmouse_ret_t synaptics_process_byte(struct psmouse *psmouse, struct pt_regs *regs) 474static psmouse_ret_t synaptics_process_byte(struct psmouse *psmouse, struct pt_regs *regs)
475{ 475{
476 struct input_dev *dev = &psmouse->dev; 476 struct input_dev *dev = psmouse->dev;
477 struct synaptics_data *priv = psmouse->private; 477 struct synaptics_data *priv = psmouse->private;
478 478
479 input_regs(dev, regs); 479 input_regs(dev, regs);
@@ -645,7 +645,7 @@ int synaptics_init(struct psmouse *psmouse)
645 SYN_ID_MAJOR(priv->identity), SYN_ID_MINOR(priv->identity), 645 SYN_ID_MAJOR(priv->identity), SYN_ID_MINOR(priv->identity),
646 priv->model_id, priv->capabilities, priv->ext_cap); 646 priv->model_id, priv->capabilities, priv->ext_cap);
647 647
648 set_input_params(&psmouse->dev, priv); 648 set_input_params(psmouse->dev, priv);
649 649
650 psmouse->protocol_handler = synaptics_process_byte; 650 psmouse->protocol_handler = synaptics_process_byte;
651 psmouse->set_rate = synaptics_set_rate; 651 psmouse->set_rate = synaptics_set_rate;
diff --git a/drivers/input/mouse/vsxxxaa.c b/drivers/input/mouse/vsxxxaa.c
index f024be9b44d2..36e9442a16b2 100644
--- a/drivers/input/mouse/vsxxxaa.c
+++ b/drivers/input/mouse/vsxxxaa.c
@@ -112,7 +112,7 @@ MODULE_LICENSE ("GPL");
112 112
113 113
114struct vsxxxaa { 114struct vsxxxaa {
115 struct input_dev dev; 115 struct input_dev *dev;
116 struct serio *serio; 116 struct serio *serio;
117#define BUFLEN 15 /* At least 5 is needed for a full tablet packet */ 117#define BUFLEN 15 /* At least 5 is needed for a full tablet packet */
118 unsigned char buf[BUFLEN]; 118 unsigned char buf[BUFLEN];
@@ -211,7 +211,7 @@ vsxxxaa_smells_like_packet (struct vsxxxaa *mouse, unsigned char type, size_t le
211static void 211static void
212vsxxxaa_handle_REL_packet (struct vsxxxaa *mouse, struct pt_regs *regs) 212vsxxxaa_handle_REL_packet (struct vsxxxaa *mouse, struct pt_regs *regs)
213{ 213{
214 struct input_dev *dev = &mouse->dev; 214 struct input_dev *dev = mouse->dev;
215 unsigned char *buf = mouse->buf; 215 unsigned char *buf = mouse->buf;
216 int left, middle, right; 216 int left, middle, right;
217 int dx, dy; 217 int dx, dy;
@@ -269,7 +269,7 @@ vsxxxaa_handle_REL_packet (struct vsxxxaa *mouse, struct pt_regs *regs)
269static void 269static void
270vsxxxaa_handle_ABS_packet (struct vsxxxaa *mouse, struct pt_regs *regs) 270vsxxxaa_handle_ABS_packet (struct vsxxxaa *mouse, struct pt_regs *regs)
271{ 271{
272 struct input_dev *dev = &mouse->dev; 272 struct input_dev *dev = mouse->dev;
273 unsigned char *buf = mouse->buf; 273 unsigned char *buf = mouse->buf;
274 int left, middle, right, touch; 274 int left, middle, right, touch;
275 int x, y; 275 int x, y;
@@ -323,7 +323,7 @@ vsxxxaa_handle_ABS_packet (struct vsxxxaa *mouse, struct pt_regs *regs)
323static void 323static void
324vsxxxaa_handle_POR_packet (struct vsxxxaa *mouse, struct pt_regs *regs) 324vsxxxaa_handle_POR_packet (struct vsxxxaa *mouse, struct pt_regs *regs)
325{ 325{
326 struct input_dev *dev = &mouse->dev; 326 struct input_dev *dev = mouse->dev;
327 unsigned char *buf = mouse->buf; 327 unsigned char *buf = mouse->buf;
328 int left, middle, right; 328 int left, middle, right;
329 unsigned char error; 329 unsigned char error;
@@ -483,9 +483,9 @@ vsxxxaa_disconnect (struct serio *serio)
483{ 483{
484 struct vsxxxaa *mouse = serio_get_drvdata (serio); 484 struct vsxxxaa *mouse = serio_get_drvdata (serio);
485 485
486 input_unregister_device (&mouse->dev);
487 serio_close (serio); 486 serio_close (serio);
488 serio_set_drvdata (serio, NULL); 487 serio_set_drvdata (serio, NULL);
488 input_unregister_device (mouse->dev);
489 kfree (mouse); 489 kfree (mouse);
490} 490}
491 491
@@ -493,61 +493,57 @@ static int
493vsxxxaa_connect (struct serio *serio, struct serio_driver *drv) 493vsxxxaa_connect (struct serio *serio, struct serio_driver *drv)
494{ 494{
495 struct vsxxxaa *mouse; 495 struct vsxxxaa *mouse;
496 int err; 496 struct input_dev *input_dev;
497 int err = -ENOMEM;
497 498
498 if (!(mouse = kmalloc (sizeof (struct vsxxxaa), GFP_KERNEL))) 499 mouse = kzalloc (sizeof (struct vsxxxaa), GFP_KERNEL);
499 return -ENOMEM; 500 input_dev = input_allocate_device ();
500 501 if (!mouse || !input_dev)
501 memset (mouse, 0, sizeof (struct vsxxxaa)); 502 goto fail;
502
503 init_input_dev (&mouse->dev);
504 set_bit (EV_KEY, mouse->dev.evbit); /* We have buttons */
505 set_bit (EV_REL, mouse->dev.evbit);
506 set_bit (EV_ABS, mouse->dev.evbit);
507 set_bit (BTN_LEFT, mouse->dev.keybit); /* We have 3 buttons */
508 set_bit (BTN_MIDDLE, mouse->dev.keybit);
509 set_bit (BTN_RIGHT, mouse->dev.keybit);
510 set_bit (BTN_TOUCH, mouse->dev.keybit); /* ...and Tablet */
511 set_bit (REL_X, mouse->dev.relbit);
512 set_bit (REL_Y, mouse->dev.relbit);
513 set_bit (ABS_X, mouse->dev.absbit);
514 set_bit (ABS_Y, mouse->dev.absbit);
515
516 mouse->dev.absmin[ABS_X] = 0;
517 mouse->dev.absmax[ABS_X] = 1023;
518 mouse->dev.absmin[ABS_Y] = 0;
519 mouse->dev.absmax[ABS_Y] = 1023;
520
521 mouse->dev.private = mouse;
522 503
504 mouse->dev = input_dev;
505 mouse->serio = serio;
523 sprintf (mouse->name, "DEC VSXXX-AA/-GA mouse or VSXXX-AB digitizer"); 506 sprintf (mouse->name, "DEC VSXXX-AA/-GA mouse or VSXXX-AB digitizer");
524 sprintf (mouse->phys, "%s/input0", serio->phys); 507 sprintf (mouse->phys, "%s/input0", serio->phys);
525 mouse->dev.name = mouse->name; 508
526 mouse->dev.phys = mouse->phys; 509 input_dev->name = mouse->name;
527 mouse->dev.id.bustype = BUS_RS232; 510 input_dev->phys = mouse->phys;
528 mouse->dev.dev = &serio->dev; 511 input_dev->id.bustype = BUS_RS232;
529 mouse->serio = serio; 512 input_dev->cdev.dev = &serio->dev;
513 input_dev->private = mouse;
514
515 set_bit (EV_KEY, input_dev->evbit); /* We have buttons */
516 set_bit (EV_REL, input_dev->evbit);
517 set_bit (EV_ABS, input_dev->evbit);
518 set_bit (BTN_LEFT, input_dev->keybit); /* We have 3 buttons */
519 set_bit (BTN_MIDDLE, input_dev->keybit);
520 set_bit (BTN_RIGHT, input_dev->keybit);
521 set_bit (BTN_TOUCH, input_dev->keybit); /* ...and Tablet */
522 set_bit (REL_X, input_dev->relbit);
523 set_bit (REL_Y, input_dev->relbit);
524 input_set_abs_params (input_dev, ABS_X, 0, 1023, 0, 0);
525 input_set_abs_params (input_dev, ABS_Y, 0, 1023, 0, 0);
530 526
531 serio_set_drvdata (serio, mouse); 527 serio_set_drvdata (serio, mouse);
532 528
533 err = serio_open (serio, drv); 529 err = serio_open (serio, drv);
534 if (err) { 530 if (err)
535 serio_set_drvdata (serio, NULL); 531 goto fail;
536 kfree (mouse);
537 return err;
538 }
539 532
540 /* 533 /*
541 * Request selftest. Standard packet format and differential 534 * Request selftest. Standard packet format and differential
542 * mode will be requested after the device ID'ed successfully. 535 * mode will be requested after the device ID'ed successfully.
543 */ 536 */
544 mouse->serio->write (mouse->serio, 'T'); /* Test */ 537 serio->write (serio, 'T'); /* Test */
545
546 input_register_device (&mouse->dev);
547 538
548 printk (KERN_INFO "input: %s on %s\n", mouse->name, mouse->phys); 539 input_register_device (input_dev);
549 540
550 return 0; 541 return 0;
542
543 fail: serio_set_drvdata (serio, NULL);
544 input_free_device (input_dev);
545 kfree (mouse);
546 return err;
551} 547}
552 548
553static struct serio_device_id vsxxaa_serio_ids[] = { 549static struct serio_device_id vsxxaa_serio_ids[] = {
diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
index c6194a9dd174..2d0af44ac4b9 100644
--- a/drivers/input/mousedev.c
+++ b/drivers/input/mousedev.c
@@ -9,7 +9,7 @@
9 * the Free Software Foundation. 9 * the Free Software Foundation.
10 */ 10 */
11 11
12#define MOUSEDEV_MINOR_BASE 32 12#define MOUSEDEV_MINOR_BASE 32
13#define MOUSEDEV_MINORS 32 13#define MOUSEDEV_MINORS 32
14#define MOUSEDEV_MIX 31 14#define MOUSEDEV_MIX 31
15 15
@@ -24,7 +24,6 @@
24#include <linux/random.h> 24#include <linux/random.h>
25#include <linux/major.h> 25#include <linux/major.h>
26#include <linux/device.h> 26#include <linux/device.h>
27#include <linux/devfs_fs_kernel.h>
28#ifdef CONFIG_INPUT_MOUSEDEV_PSAUX 27#ifdef CONFIG_INPUT_MOUSEDEV_PSAUX
29#include <linux/miscdevice.h> 28#include <linux/miscdevice.h>
30#endif 29#endif
@@ -621,6 +620,7 @@ static struct file_operations mousedev_fops = {
621static struct input_handle *mousedev_connect(struct input_handler *handler, struct input_dev *dev, struct input_device_id *id) 620static struct input_handle *mousedev_connect(struct input_handler *handler, struct input_dev *dev, struct input_device_id *id)
622{ 621{
623 struct mousedev *mousedev; 622 struct mousedev *mousedev;
623 struct class_device *cdev;
624 int minor = 0; 624 int minor = 0;
625 625
626 for (minor = 0; minor < MOUSEDEV_MINORS && mousedev_table[minor]; minor++); 626 for (minor = 0; minor < MOUSEDEV_MINORS && mousedev_table[minor]; minor++);
@@ -649,11 +649,13 @@ static struct input_handle *mousedev_connect(struct input_handler *handler, stru
649 649
650 mousedev_table[minor] = mousedev; 650 mousedev_table[minor] = mousedev;
651 651
652 devfs_mk_cdev(MKDEV(INPUT_MAJOR, MOUSEDEV_MINOR_BASE + minor), 652 cdev = class_device_create(&input_class, &dev->cdev,
653 S_IFCHR|S_IRUGO|S_IWUSR, "input/mouse%d", minor);
654 class_device_create(input_class,
655 MKDEV(INPUT_MAJOR, MOUSEDEV_MINOR_BASE + minor), 653 MKDEV(INPUT_MAJOR, MOUSEDEV_MINOR_BASE + minor),
656 dev->dev, "mouse%d", minor); 654 dev->cdev.dev, mousedev->name);
655
656 /* temporary symlink to keep userspace happy */
657 sysfs_create_link(&input_class.subsys.kset.kobj, &cdev->kobj,
658 mousedev->name);
657 659
658 return &mousedev->handle; 660 return &mousedev->handle;
659} 661}
@@ -663,9 +665,9 @@ static void mousedev_disconnect(struct input_handle *handle)
663 struct mousedev *mousedev = handle->private; 665 struct mousedev *mousedev = handle->private;
664 struct mousedev_list *list; 666 struct mousedev_list *list;
665 667
666 class_device_destroy(input_class, 668 sysfs_remove_link(&input_class.subsys.kset.kobj, mousedev->name);
669 class_device_destroy(&input_class,
667 MKDEV(INPUT_MAJOR, MOUSEDEV_MINOR_BASE + mousedev->minor)); 670 MKDEV(INPUT_MAJOR, MOUSEDEV_MINOR_BASE + mousedev->minor));
668 devfs_remove("input/mouse%d", mousedev->minor);
669 mousedev->exist = 0; 671 mousedev->exist = 0;
670 672
671 if (mousedev->open) { 673 if (mousedev->open) {
@@ -738,9 +740,7 @@ static int __init mousedev_init(void)
738 mousedev_mix.exist = 1; 740 mousedev_mix.exist = 1;
739 mousedev_mix.minor = MOUSEDEV_MIX; 741 mousedev_mix.minor = MOUSEDEV_MIX;
740 742
741 devfs_mk_cdev(MKDEV(INPUT_MAJOR, MOUSEDEV_MINOR_BASE + MOUSEDEV_MIX), 743 class_device_create(&input_class, NULL,
742 S_IFCHR|S_IRUGO|S_IWUSR, "input/mice");
743 class_device_create(input_class,
744 MKDEV(INPUT_MAJOR, MOUSEDEV_MINOR_BASE + MOUSEDEV_MIX), NULL, "mice"); 744 MKDEV(INPUT_MAJOR, MOUSEDEV_MINOR_BASE + MOUSEDEV_MIX), NULL, "mice");
745 745
746#ifdef CONFIG_INPUT_MOUSEDEV_PSAUX 746#ifdef CONFIG_INPUT_MOUSEDEV_PSAUX
@@ -759,8 +759,7 @@ static void __exit mousedev_exit(void)
759 if (psaux_registered) 759 if (psaux_registered)
760 misc_deregister(&psaux_mouse); 760 misc_deregister(&psaux_mouse);
761#endif 761#endif
762 devfs_remove("input/mice"); 762 class_device_destroy(&input_class,
763 class_device_destroy(input_class,
764 MKDEV(INPUT_MAJOR, MOUSEDEV_MINOR_BASE + MOUSEDEV_MIX)); 763 MKDEV(INPUT_MAJOR, MOUSEDEV_MINOR_BASE + MOUSEDEV_MIX));
765 input_unregister_handler(&mousedev_handler); 764 input_unregister_handler(&mousedev_handler);
766} 765}
diff --git a/drivers/input/serio/i8042.c b/drivers/input/serio/i8042.c
index 40d451ce07ff..4bc40f159996 100644
--- a/drivers/input/serio/i8042.c
+++ b/drivers/input/serio/i8042.c
@@ -911,12 +911,10 @@ static long i8042_panic_blink(long count)
911 * Here we try to restore the original BIOS settings 911 * Here we try to restore the original BIOS settings
912 */ 912 */
913 913
914static int i8042_suspend(struct device *dev, pm_message_t state, u32 level) 914static int i8042_suspend(struct device *dev, pm_message_t state)
915{ 915{
916 if (level == SUSPEND_DISABLE) { 916 del_timer_sync(&i8042_timer);
917 del_timer_sync(&i8042_timer); 917 i8042_controller_reset();
918 i8042_controller_reset();
919 }
920 918
921 return 0; 919 return 0;
922} 920}
@@ -926,13 +924,10 @@ static int i8042_suspend(struct device *dev, pm_message_t state, u32 level)
926 * Here we try to reset everything back to a state in which suspended 924 * Here we try to reset everything back to a state in which suspended
927 */ 925 */
928 926
929static int i8042_resume(struct device *dev, u32 level) 927static int i8042_resume(struct device *dev)
930{ 928{
931 int i; 929 int i;
932 930
933 if (level != RESUME_ENABLE)
934 return 0;
935
936 if (i8042_ctl_test()) 931 if (i8042_ctl_test())
937 return -1; 932 return -1;
938 933
diff --git a/drivers/input/touchscreen/corgi_ts.c b/drivers/input/touchscreen/corgi_ts.c
index 4c7fbe550365..0ba3e6562bff 100644
--- a/drivers/input/touchscreen/corgi_ts.c
+++ b/drivers/input/touchscreen/corgi_ts.c
@@ -41,8 +41,7 @@ struct ts_event {
41}; 41};
42 42
43struct corgi_ts { 43struct corgi_ts {
44 char phys[32]; 44 struct input_dev *input;
45 struct input_dev input;
46 struct timer_list timer; 45 struct timer_list timer;
47 struct ts_event tc; 46 struct ts_event tc;
48 int pendown; 47 int pendown;
@@ -182,14 +181,12 @@ static void new_data(struct corgi_ts *corgi_ts, struct pt_regs *regs)
182 if (!corgi_ts->tc.pressure && corgi_ts->pendown == 0) 181 if (!corgi_ts->tc.pressure && corgi_ts->pendown == 0)
183 return; 182 return;
184 183
185 if (regs) 184 input_regs(corgi_ts->input, regs);
186 input_regs(&corgi_ts->input, regs); 185 input_report_abs(corgi_ts->input, ABS_X, corgi_ts->tc.x);
187 186 input_report_abs(corgi_ts->input, ABS_Y, corgi_ts->tc.y);
188 input_report_abs(&corgi_ts->input, ABS_X, corgi_ts->tc.x); 187 input_report_abs(corgi_ts->input, ABS_PRESSURE, corgi_ts->tc.pressure);
189 input_report_abs(&corgi_ts->input, ABS_Y, corgi_ts->tc.y); 188 input_report_key(corgi_ts->input, BTN_TOUCH, (corgi_ts->pendown != 0));
190 input_report_abs(&corgi_ts->input, ABS_PRESSURE, corgi_ts->tc.pressure); 189 input_sync(corgi_ts->input);
191 input_report_key(&corgi_ts->input, BTN_TOUCH, (corgi_ts->pendown != 0));
192 input_sync(&corgi_ts->input);
193} 190}
194 191
195static void ts_interrupt_main(struct corgi_ts *corgi_ts, int isTimer, struct pt_regs *regs) 192static void ts_interrupt_main(struct corgi_ts *corgi_ts, int isTimer, struct pt_regs *regs)
@@ -234,34 +231,32 @@ static irqreturn_t ts_interrupt(int irq, void *dev_id, struct pt_regs *regs)
234} 231}
235 232
236#ifdef CONFIG_PM 233#ifdef CONFIG_PM
237static int corgits_suspend(struct device *dev, pm_message_t state, uint32_t level) 234static int corgits_suspend(struct device *dev, pm_message_t state)
238{ 235{
239 if (level == SUSPEND_POWER_DOWN) { 236 struct corgi_ts *corgi_ts = dev_get_drvdata(dev);
240 struct corgi_ts *corgi_ts = dev_get_drvdata(dev);
241
242 if (corgi_ts->pendown) {
243 del_timer_sync(&corgi_ts->timer);
244 corgi_ts->tc.pressure = 0;
245 new_data(corgi_ts, NULL);
246 corgi_ts->pendown = 0;
247 }
248 corgi_ts->power_mode = PWR_MODE_SUSPEND;
249 237
250 corgi_ssp_ads7846_putget((1u << ADSCTRL_ADR_SH) | ADSCTRL_STS); 238 if (corgi_ts->pendown) {
239 del_timer_sync(&corgi_ts->timer);
240 corgi_ts->tc.pressure = 0;
241 new_data(corgi_ts, NULL);
242 corgi_ts->pendown = 0;
251 } 243 }
244 corgi_ts->power_mode = PWR_MODE_SUSPEND;
245
246 corgi_ssp_ads7846_putget((1u << ADSCTRL_ADR_SH) | ADSCTRL_STS);
247
252 return 0; 248 return 0;
253} 249}
254 250
255static int corgits_resume(struct device *dev, uint32_t level) 251static int corgits_resume(struct device *dev)
256{ 252{
257 if (level == RESUME_POWER_ON) { 253 struct corgi_ts *corgi_ts = dev_get_drvdata(dev);
258 struct corgi_ts *corgi_ts = dev_get_drvdata(dev); 254
255 corgi_ssp_ads7846_putget((4u << ADSCTRL_ADR_SH) | ADSCTRL_STS);
256 /* Enable Falling Edge */
257 set_irq_type(corgi_ts->irq_gpio, IRQT_FALLING);
258 corgi_ts->power_mode = PWR_MODE_ACTIVE;
259 259
260 corgi_ssp_ads7846_putget((4u << ADSCTRL_ADR_SH) | ADSCTRL_STS);
261 /* Enable Falling Edge */
262 set_irq_type(corgi_ts->irq_gpio, IRQT_FALLING);
263 corgi_ts->power_mode = PWR_MODE_ACTIVE;
264 }
265 return 0; 260 return 0;
266} 261}
267#else 262#else
@@ -273,39 +268,44 @@ static int __init corgits_probe(struct device *dev)
273{ 268{
274 struct corgi_ts *corgi_ts; 269 struct corgi_ts *corgi_ts;
275 struct platform_device *pdev = to_platform_device(dev); 270 struct platform_device *pdev = to_platform_device(dev);
271 struct input_dev *input_dev;
272 int err = -ENOMEM;
276 273
277 if (!(corgi_ts = kmalloc(sizeof(struct corgi_ts), GFP_KERNEL))) 274 corgi_ts = kzalloc(sizeof(struct corgi_ts), GFP_KERNEL);
278 return -ENOMEM; 275 input_dev = input_allocate_device();
276 if (!corgi_ts || !input_dev)
277 goto fail;
279 278
280 dev_set_drvdata(dev, corgi_ts); 279 dev_set_drvdata(dev, corgi_ts);
281 280
282 memset(corgi_ts, 0, sizeof(struct corgi_ts));
283
284 corgi_ts->machinfo = dev->platform_data; 281 corgi_ts->machinfo = dev->platform_data;
285 corgi_ts->irq_gpio = platform_get_irq(pdev, 0); 282 corgi_ts->irq_gpio = platform_get_irq(pdev, 0);
286 283
287 if (corgi_ts->irq_gpio < 0) { 284 if (corgi_ts->irq_gpio < 0) {
288 kfree(corgi_ts); 285 err = -ENODEV;
289 return -ENODEV; 286 goto fail;
290 } 287 }
291 288
292 init_input_dev(&corgi_ts->input); 289 corgi_ts->input = input_dev;
293 corgi_ts->input.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
294 corgi_ts->input.keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
295 input_set_abs_params(&corgi_ts->input, ABS_X, X_AXIS_MIN, X_AXIS_MAX, 0, 0);
296 input_set_abs_params(&corgi_ts->input, ABS_Y, Y_AXIS_MIN, Y_AXIS_MAX, 0, 0);
297 input_set_abs_params(&corgi_ts->input, ABS_PRESSURE, PRESSURE_MIN, PRESSURE_MAX, 0, 0);
298 290
299 strcpy(corgi_ts->phys, "corgits/input0"); 291 init_timer(&corgi_ts->timer);
292 corgi_ts->timer.data = (unsigned long) corgi_ts;
293 corgi_ts->timer.function = corgi_ts_timer;
300 294
301 corgi_ts->input.private = corgi_ts; 295 input_dev->name = "Corgi Touchscreen";
302 corgi_ts->input.name = "Corgi Touchscreen"; 296 input_dev->phys = "corgits/input0";
303 corgi_ts->input.dev = dev; 297 input_dev->id.bustype = BUS_HOST;
304 corgi_ts->input.phys = corgi_ts->phys; 298 input_dev->id.vendor = 0x0001;
305 corgi_ts->input.id.bustype = BUS_HOST; 299 input_dev->id.product = 0x0002;
306 corgi_ts->input.id.vendor = 0x0001; 300 input_dev->id.version = 0x0100;
307 corgi_ts->input.id.product = 0x0002; 301 input_dev->cdev.dev = dev;
308 corgi_ts->input.id.version = 0x0100; 302 input_dev->private = corgi_ts;
303
304 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
305 input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
306 input_set_abs_params(input_dev, ABS_X, X_AXIS_MIN, X_AXIS_MAX, 0, 0);
307 input_set_abs_params(input_dev, ABS_Y, Y_AXIS_MIN, Y_AXIS_MAX, 0, 0);
308 input_set_abs_params(input_dev, ABS_PRESSURE, PRESSURE_MIN, PRESSURE_MAX, 0, 0);
309 309
310 pxa_gpio_mode(IRQ_TO_GPIO(corgi_ts->irq_gpio) | GPIO_IN); 310 pxa_gpio_mode(IRQ_TO_GPIO(corgi_ts->irq_gpio) | GPIO_IN);
311 311
@@ -319,25 +319,24 @@ static int __init corgits_probe(struct device *dev)
319 corgi_ssp_ads7846_putget((5u << ADSCTRL_ADR_SH) | ADSCTRL_STS); 319 corgi_ssp_ads7846_putget((5u << ADSCTRL_ADR_SH) | ADSCTRL_STS);
320 mdelay(5); 320 mdelay(5);
321 321
322 init_timer(&corgi_ts->timer);
323 corgi_ts->timer.data = (unsigned long) corgi_ts;
324 corgi_ts->timer.function = corgi_ts_timer;
325
326 input_register_device(&corgi_ts->input);
327 corgi_ts->power_mode = PWR_MODE_ACTIVE;
328
329 if (request_irq(corgi_ts->irq_gpio, ts_interrupt, SA_INTERRUPT, "ts", corgi_ts)) { 322 if (request_irq(corgi_ts->irq_gpio, ts_interrupt, SA_INTERRUPT, "ts", corgi_ts)) {
330 input_unregister_device(&corgi_ts->input); 323 err = -EBUSY;
331 kfree(corgi_ts); 324 goto fail;
332 return -EBUSY;
333 } 325 }
334 326
327 input_register_device(corgi_ts->input);
328
329 corgi_ts->power_mode = PWR_MODE_ACTIVE;
330
335 /* Enable Falling Edge */ 331 /* Enable Falling Edge */
336 set_irq_type(corgi_ts->irq_gpio, IRQT_FALLING); 332 set_irq_type(corgi_ts->irq_gpio, IRQT_FALLING);
337 333
338 printk(KERN_INFO "input: Corgi Touchscreen Registered\n");
339
340 return 0; 334 return 0;
335
336 fail: input_free_device(input_dev);
337 kfree(corgi_ts);
338 return err;
339
341} 340}
342 341
343static int corgits_remove(struct device *dev) 342static int corgits_remove(struct device *dev)
@@ -347,7 +346,7 @@ static int corgits_remove(struct device *dev)
347 free_irq(corgi_ts->irq_gpio, NULL); 346 free_irq(corgi_ts->irq_gpio, NULL);
348 del_timer_sync(&corgi_ts->timer); 347 del_timer_sync(&corgi_ts->timer);
349 corgi_ts->machinfo->put_hsync(); 348 corgi_ts->machinfo->put_hsync();
350 input_unregister_device(&corgi_ts->input); 349 input_unregister_device(corgi_ts->input);
351 kfree(corgi_ts); 350 kfree(corgi_ts);
352 return 0; 351 return 0;
353} 352}
diff --git a/drivers/input/touchscreen/elo.c b/drivers/input/touchscreen/elo.c
index 3cdc9cab688d..c86a2eb310fd 100644
--- a/drivers/input/touchscreen/elo.c
+++ b/drivers/input/touchscreen/elo.c
@@ -36,14 +36,12 @@ MODULE_LICENSE("GPL");
36 36
37#define ELO_MAX_LENGTH 10 37#define ELO_MAX_LENGTH 10
38 38
39static char *elo_name = "Elo Serial TouchScreen";
40
41/* 39/*
42 * Per-touchscreen data. 40 * Per-touchscreen data.
43 */ 41 */
44 42
45struct elo { 43struct elo {
46 struct input_dev dev; 44 struct input_dev *dev;
47 struct serio *serio; 45 struct serio *serio;
48 int id; 46 int id;
49 int idx; 47 int idx;
@@ -54,7 +52,7 @@ struct elo {
54 52
55static void elo_process_data_10(struct elo* elo, unsigned char data, struct pt_regs *regs) 53static void elo_process_data_10(struct elo* elo, unsigned char data, struct pt_regs *regs)
56{ 54{
57 struct input_dev *dev = &elo->dev; 55 struct input_dev *dev = elo->dev;
58 56
59 elo->csum += elo->data[elo->idx] = data; 57 elo->csum += elo->data[elo->idx] = data;
60 58
@@ -80,7 +78,7 @@ static void elo_process_data_10(struct elo* elo, unsigned char data, struct pt_r
80 input_report_abs(dev, ABS_X, (elo->data[4] << 8) | elo->data[3]); 78 input_report_abs(dev, ABS_X, (elo->data[4] << 8) | elo->data[3]);
81 input_report_abs(dev, ABS_Y, (elo->data[6] << 8) | elo->data[5]); 79 input_report_abs(dev, ABS_Y, (elo->data[6] << 8) | elo->data[5]);
82 input_report_abs(dev, ABS_PRESSURE, (elo->data[8] << 8) | elo->data[7]); 80 input_report_abs(dev, ABS_PRESSURE, (elo->data[8] << 8) | elo->data[7]);
83 input_report_key(dev, BTN_TOUCH, elo->data[2] & 3); 81 input_report_key(dev, BTN_TOUCH, elo->data[8] || elo->data[7]);
84 input_sync(dev); 82 input_sync(dev);
85 } 83 }
86 elo->idx = 0; 84 elo->idx = 0;
@@ -91,7 +89,7 @@ static void elo_process_data_10(struct elo* elo, unsigned char data, struct pt_r
91 89
92static void elo_process_data_6(struct elo* elo, unsigned char data, struct pt_regs *regs) 90static void elo_process_data_6(struct elo* elo, unsigned char data, struct pt_regs *regs)
93{ 91{
94 struct input_dev *dev = &elo->dev; 92 struct input_dev *dev = elo->dev;
95 93
96 elo->data[elo->idx] = data; 94 elo->data[elo->idx] = data;
97 95
@@ -129,7 +127,7 @@ static void elo_process_data_6(struct elo* elo, unsigned char data, struct pt_re
129 case 5: 127 case 5:
130 if ((data & 0xf0) == 0) { 128 if ((data & 0xf0) == 0) {
131 input_report_abs(dev, ABS_PRESSURE, elo->data[5]); 129 input_report_abs(dev, ABS_PRESSURE, elo->data[5]);
132 input_report_key(dev, BTN_TOUCH, elo->data[5]); 130 input_report_key(dev, BTN_TOUCH, !!elo->data[5]);
133 } 131 }
134 input_sync(dev); 132 input_sync(dev);
135 elo->idx = 0; 133 elo->idx = 0;
@@ -139,7 +137,7 @@ static void elo_process_data_6(struct elo* elo, unsigned char data, struct pt_re
139 137
140static void elo_process_data_3(struct elo* elo, unsigned char data, struct pt_regs *regs) 138static void elo_process_data_3(struct elo* elo, unsigned char data, struct pt_regs *regs)
141{ 139{
142 struct input_dev *dev = &elo->dev; 140 struct input_dev *dev = elo->dev;
143 141
144 elo->data[elo->idx] = data; 142 elo->data[elo->idx] = data;
145 143
@@ -191,7 +189,7 @@ static void elo_disconnect(struct serio *serio)
191{ 189{
192 struct elo* elo = serio_get_drvdata(serio); 190 struct elo* elo = serio_get_drvdata(serio);
193 191
194 input_unregister_device(&elo->dev); 192 input_unregister_device(elo->dev);
195 serio_close(serio); 193 serio_close(serio);
196 serio_set_drvdata(serio, NULL); 194 serio_set_drvdata(serio, NULL);
197 kfree(elo); 195 kfree(elo);
@@ -206,67 +204,68 @@ static void elo_disconnect(struct serio *serio)
206static int elo_connect(struct serio *serio, struct serio_driver *drv) 204static int elo_connect(struct serio *serio, struct serio_driver *drv)
207{ 205{
208 struct elo *elo; 206 struct elo *elo;
207 struct input_dev *input_dev;
209 int err; 208 int err;
210 209
211 if (!(elo = kmalloc(sizeof(struct elo), GFP_KERNEL))) 210 elo = kzalloc(sizeof(struct elo), GFP_KERNEL);
212 return -ENOMEM; 211 input_dev = input_allocate_device();
212 if (!elo || !input_dev) {
213 err = -ENOMEM;
214 goto fail;
215 }
213 216
214 memset(elo, 0, sizeof(struct elo)); 217 elo->serio = serio;
218 elo->id = serio->id.id;
219 elo->dev = input_dev;
220 snprintf(elo->phys, sizeof(elo->phys), "%s/input0", serio->phys);
215 221
216 init_input_dev(&elo->dev); 222 input_dev->private = elo;
217 elo->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 223 input_dev->name = "Elo Serial TouchScreen";
218 elo->dev.keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH); 224 input_dev->phys = elo->phys;
225 input_dev->id.bustype = BUS_RS232;
226 input_dev->id.vendor = SERIO_ELO;
227 input_dev->id.product = elo->id;
228 input_dev->id.version = 0x0100;
229 input_dev->cdev.dev = &serio->dev;
219 230
220 elo->id = serio->id.id; 231 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
232 input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
221 233
222 switch (elo->id) { 234 switch (elo->id) {
223 235
224 case 0: /* 10-byte protocol */ 236 case 0: /* 10-byte protocol */
225 input_set_abs_params(&elo->dev, ABS_X, 96, 4000, 0, 0); 237 input_set_abs_params(input_dev, ABS_X, 96, 4000, 0, 0);
226 input_set_abs_params(&elo->dev, ABS_Y, 96, 4000, 0, 0); 238 input_set_abs_params(input_dev, ABS_Y, 96, 4000, 0, 0);
227 input_set_abs_params(&elo->dev, ABS_PRESSURE, 0, 255, 0, 0); 239 input_set_abs_params(input_dev, ABS_PRESSURE, 0, 255, 0, 0);
228 break; 240 break;
229 241
230 case 1: /* 6-byte protocol */ 242 case 1: /* 6-byte protocol */
231 input_set_abs_params(&elo->dev, ABS_PRESSURE, 0, 15, 0, 0); 243 input_set_abs_params(input_dev, ABS_PRESSURE, 0, 15, 0, 0);
232 244
233 case 2: /* 4-byte protocol */ 245 case 2: /* 4-byte protocol */
234 input_set_abs_params(&elo->dev, ABS_X, 96, 4000, 0, 0); 246 input_set_abs_params(input_dev, ABS_X, 96, 4000, 0, 0);
235 input_set_abs_params(&elo->dev, ABS_Y, 96, 4000, 0, 0); 247 input_set_abs_params(input_dev, ABS_Y, 96, 4000, 0, 0);
236 break; 248 break;
237 249
238 case 3: /* 3-byte protocol */ 250 case 3: /* 3-byte protocol */
239 input_set_abs_params(&elo->dev, ABS_X, 0, 255, 0, 0); 251 input_set_abs_params(input_dev, ABS_X, 0, 255, 0, 0);
240 input_set_abs_params(&elo->dev, ABS_Y, 0, 255, 0, 0); 252 input_set_abs_params(input_dev, ABS_Y, 0, 255, 0, 0);
241 break; 253 break;
242 } 254 }
243 255
244 elo->serio = serio;
245
246 sprintf(elo->phys, "%s/input0", serio->phys);
247
248 elo->dev.private = elo;
249 elo->dev.name = elo_name;
250 elo->dev.phys = elo->phys;
251 elo->dev.id.bustype = BUS_RS232;
252 elo->dev.id.vendor = SERIO_ELO;
253 elo->dev.id.product = elo->id;
254 elo->dev.id.version = 0x0100;
255
256 serio_set_drvdata(serio, elo); 256 serio_set_drvdata(serio, elo);
257 257
258 err = serio_open(serio, drv); 258 err = serio_open(serio, drv);
259 if (err) { 259 if (err)
260 serio_set_drvdata(serio, NULL); 260 goto fail;
261 kfree(elo);
262 return err;
263 }
264
265 input_register_device(&elo->dev);
266
267 printk(KERN_INFO "input: %s on %s\n", elo_name, serio->phys);
268 261
262 input_register_device(elo->dev);
269 return 0; 263 return 0;
264
265 fail: serio_set_drvdata(serio, NULL);
266 input_free_device(input_dev);
267 kfree(elo);
268 return err;
270} 269}
271 270
272/* 271/*
diff --git a/drivers/input/touchscreen/gunze.c b/drivers/input/touchscreen/gunze.c
index 53a27e43dd23..466da190ceec 100644
--- a/drivers/input/touchscreen/gunze.c
+++ b/drivers/input/touchscreen/gunze.c
@@ -48,14 +48,12 @@ MODULE_LICENSE("GPL");
48 48
49#define GUNZE_MAX_LENGTH 10 49#define GUNZE_MAX_LENGTH 10
50 50
51static char *gunze_name = "Gunze AHL-51S TouchScreen";
52
53/* 51/*
54 * Per-touchscreen data. 52 * Per-touchscreen data.
55 */ 53 */
56 54
57struct gunze { 55struct gunze {
58 struct input_dev dev; 56 struct input_dev *dev;
59 struct serio *serio; 57 struct serio *serio;
60 int idx; 58 int idx;
61 unsigned char data[GUNZE_MAX_LENGTH]; 59 unsigned char data[GUNZE_MAX_LENGTH];
@@ -64,7 +62,7 @@ struct gunze {
64 62
65static void gunze_process_packet(struct gunze* gunze, struct pt_regs *regs) 63static void gunze_process_packet(struct gunze* gunze, struct pt_regs *regs)
66{ 64{
67 struct input_dev *dev = &gunze->dev; 65 struct input_dev *dev = gunze->dev;
68 66
69 if (gunze->idx != GUNZE_MAX_LENGTH || gunze->data[5] != ',' || 67 if (gunze->idx != GUNZE_MAX_LENGTH || gunze->data[5] != ',' ||
70 (gunze->data[0] != 'T' && gunze->data[0] != 'R')) { 68 (gunze->data[0] != 'T' && gunze->data[0] != 'R')) {
@@ -100,11 +98,13 @@ static irqreturn_t gunze_interrupt(struct serio *serio,
100 98
101static void gunze_disconnect(struct serio *serio) 99static void gunze_disconnect(struct serio *serio)
102{ 100{
103 struct gunze* gunze = serio_get_drvdata(serio); 101 struct gunze *gunze = serio_get_drvdata(serio);
104 102
105 input_unregister_device(&gunze->dev); 103 input_get_device(gunze->dev);
104 input_unregister_device(gunze->dev);
106 serio_close(serio); 105 serio_close(serio);
107 serio_set_drvdata(serio, NULL); 106 serio_set_drvdata(serio, NULL);
107 input_put_device(gunze->dev);
108 kfree(gunze); 108 kfree(gunze);
109} 109}
110 110
@@ -117,45 +117,45 @@ static void gunze_disconnect(struct serio *serio)
117static int gunze_connect(struct serio *serio, struct serio_driver *drv) 117static int gunze_connect(struct serio *serio, struct serio_driver *drv)
118{ 118{
119 struct gunze *gunze; 119 struct gunze *gunze;
120 struct input_dev *input_dev;
120 int err; 121 int err;
121 122
122 if (!(gunze = kmalloc(sizeof(struct gunze), GFP_KERNEL))) 123 gunze = kzalloc(sizeof(struct gunze), GFP_KERNEL);
123 return -ENOMEM; 124 input_dev = input_allocate_device();
124 125 if (!gunze || !input_dev) {
125 memset(gunze, 0, sizeof(struct gunze)); 126 err = -ENOMEM;
126 127 goto fail;
127 init_input_dev(&gunze->dev); 128 }
128 gunze->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
129 gunze->dev.keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
130 input_set_abs_params(&gunze->dev, ABS_X, 24, 1000, 0, 0);
131 input_set_abs_params(&gunze->dev, ABS_Y, 24, 1000, 0, 0);
132 129
133 gunze->serio = serio; 130 gunze->serio = serio;
134 131 gunze->dev = input_dev;
135 sprintf(gunze->phys, "%s/input0", serio->phys); 132 sprintf(gunze->phys, "%s/input0", serio->phys);
136 133
137 gunze->dev.private = gunze; 134 input_dev->private = gunze;
138 gunze->dev.name = gunze_name; 135 input_dev->name = "Gunze AHL-51S TouchScreen";
139 gunze->dev.phys = gunze->phys; 136 input_dev->phys = gunze->phys;
140 gunze->dev.id.bustype = BUS_RS232; 137 input_dev->id.bustype = BUS_RS232;
141 gunze->dev.id.vendor = SERIO_GUNZE; 138 input_dev->id.vendor = SERIO_GUNZE;
142 gunze->dev.id.product = 0x0051; 139 input_dev->id.product = 0x0051;
143 gunze->dev.id.version = 0x0100; 140 input_dev->id.version = 0x0100;
141 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
142 input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
143 input_set_abs_params(input_dev, ABS_X, 24, 1000, 0, 0);
144 input_set_abs_params(input_dev, ABS_Y, 24, 1000, 0, 0);
144 145
145 serio_set_drvdata(serio, gunze); 146 serio_set_drvdata(serio, gunze);
146 147
147 err = serio_open(serio, drv); 148 err = serio_open(serio, drv);
148 if (err) { 149 if (err)
149 serio_set_drvdata(serio, NULL); 150 goto fail;
150 kfree(gunze);
151 return err;
152 }
153
154 input_register_device(&gunze->dev);
155
156 printk(KERN_INFO "input: %s on %s\n", gunze_name, serio->phys);
157 151
152 input_register_device(gunze->dev);
158 return 0; 153 return 0;
154
155 fail: serio_set_drvdata(serio, NULL);
156 input_free_device(input_dev);
157 kfree(gunze);
158 return err;
159} 159}
160 160
161/* 161/*
diff --git a/drivers/input/touchscreen/h3600_ts_input.c b/drivers/input/touchscreen/h3600_ts_input.c
index bcfa1e36f957..a18d56bdafd9 100644
--- a/drivers/input/touchscreen/h3600_ts_input.c
+++ b/drivers/input/touchscreen/h3600_ts_input.c
@@ -39,7 +39,6 @@
39#include <linux/serio.h> 39#include <linux/serio.h>
40#include <linux/init.h> 40#include <linux/init.h>
41#include <linux/delay.h> 41#include <linux/delay.h>
42#include <linux/pm.h>
43 42
44/* SA1100 serial defines */ 43/* SA1100 serial defines */
45#include <asm/arch/hardware.h> 44#include <asm/arch/hardware.h>
@@ -93,16 +92,12 @@ MODULE_LICENSE("GPL");
93#define H3600_SCANCODE_LEFT 8 /* 8 -> left */ 92#define H3600_SCANCODE_LEFT 8 /* 8 -> left */
94#define H3600_SCANCODE_DOWN 9 /* 9 -> down */ 93#define H3600_SCANCODE_DOWN 9 /* 9 -> down */
95 94
96static char *h3600_name = "H3600 TouchScreen";
97
98/* 95/*
99 * Per-touchscreen data. 96 * Per-touchscreen data.
100 */ 97 */
101struct h3600_dev { 98struct h3600_dev {
102 struct input_dev dev; 99 struct input_dev *dev;
103 struct pm_dev *pm_dev;
104 struct serio *serio; 100 struct serio *serio;
105 struct pm_dev *pm_dev;
106 unsigned char event; /* event ID from packet */ 101 unsigned char event; /* event ID from packet */
107 unsigned char chksum; 102 unsigned char chksum;
108 unsigned char len; 103 unsigned char len;
@@ -163,33 +158,6 @@ unsigned int h3600_flite_power(struct input_dev *dev, enum flite_pwr pwr)
163 return 0; 158 return 0;
164} 159}
165 160
166static int suspended = 0;
167static int h3600ts_pm_callback(struct pm_dev *pm_dev, pm_request_t req,
168 void *data)
169{
170 struct input_dev *dev = (struct input_dev *) data;
171
172 switch (req) {
173 case PM_SUSPEND: /* enter D1-D3 */
174 suspended = 1;
175 h3600_flite_power(dev, FLITE_PWR_OFF);
176 break;
177 case PM_BLANK:
178 if (!suspended)
179 h3600_flite_power(dev, FLITE_PWR_OFF);
180 break;
181 case PM_RESUME: /* enter D0 */
182 /* same as unblank */
183 case PM_UNBLANK:
184 if (suspended) {
185 //initSerial();
186 suspended = 0;
187 }
188 h3600_flite_power(dev, FLITE_PWR_ON);
189 break;
190 }
191 return 0;
192}
193#endif 161#endif
194 162
195/* 163/*
@@ -199,7 +167,7 @@ static int h3600ts_pm_callback(struct pm_dev *pm_dev, pm_request_t req,
199 */ 167 */
200static void h3600ts_process_packet(struct h3600_dev *ts, struct pt_regs *regs) 168static void h3600ts_process_packet(struct h3600_dev *ts, struct pt_regs *regs)
201{ 169{
202 struct input_dev *dev = &ts->dev; 170 struct input_dev *dev = ts->dev;
203 static int touched = 0; 171 static int touched = 0;
204 int key, down = 0; 172 int key, down = 0;
205 173
@@ -295,6 +263,7 @@ static void h3600ts_process_packet(struct h3600_dev *ts, struct pt_regs *regs)
295static int h3600ts_event(struct input_dev *dev, unsigned int type, 263static int h3600ts_event(struct input_dev *dev, unsigned int type,
296 unsigned int code, int value) 264 unsigned int code, int value)
297{ 265{
266#if 0
298 struct h3600_dev *ts = dev->private; 267 struct h3600_dev *ts = dev->private;
299 268
300 switch (type) { 269 switch (type) {
@@ -304,6 +273,8 @@ static int h3600ts_event(struct input_dev *dev, unsigned int type,
304 } 273 }
305 } 274 }
306 return -1; 275 return -1;
276#endif
277 return 0;
307} 278}
308 279
309/* 280/*
@@ -380,14 +351,48 @@ static irqreturn_t h3600ts_interrupt(struct serio *serio, unsigned char data,
380static int h3600ts_connect(struct serio *serio, struct serio_driver *drv) 351static int h3600ts_connect(struct serio *serio, struct serio_driver *drv)
381{ 352{
382 struct h3600_dev *ts; 353 struct h3600_dev *ts;
354 struct input_dev *input_dev;
383 int err; 355 int err;
384 356
385 if (!(ts = kmalloc(sizeof(struct h3600_dev), GFP_KERNEL))) 357 ts = kzalloc(sizeof(struct h3600_dev), GFP_KERNEL);
386 return -ENOMEM; 358 input_dev = input_allocate_device();
359 if (!ts || !input_dev) {
360 err = -ENOMEM;
361 goto fail1;
362 }
387 363
388 memset(ts, 0, sizeof(struct h3600_dev)); 364 ts->serio = serio;
365 ts->dev = input_dev;
366 sprintf(ts->phys, "%s/input0", serio->phys);
389 367
390 init_input_dev(&ts->dev); 368 input_dev->name = "H3600 TouchScreen";
369 input_dev->phys = ts->phys;
370 input_dev->id.bustype = BUS_RS232;
371 input_dev->id.vendor = SERIO_H3600;
372 input_dev->id.product = 0x0666; /* FIXME !!! We can ask the hardware */
373 input_dev->id.version = 0x0100;
374 input_dev->cdev.dev = &serio->dev;
375 input_dev->private = ts;
376
377 input_dev->event = h3600ts_event;
378
379 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_LED) | BIT(EV_PWR);
380 input_dev->ledbit[0] = BIT(LED_SLEEP);
381 input_set_abs_params(input_dev, ABS_X, 60, 985, 0, 0);
382 input_set_abs_params(input_dev, ABS_Y, 35, 1024, 0, 0);
383
384 set_bit(KEY_RECORD, input_dev->keybit);
385 set_bit(KEY_Q, input_dev->keybit);
386 set_bit(KEY_PROG1, input_dev->keybit);
387 set_bit(KEY_PROG2, input_dev->keybit);
388 set_bit(KEY_PROG3, input_dev->keybit);
389 set_bit(KEY_UP, input_dev->keybit);
390 set_bit(KEY_RIGHT, input_dev->keybit);
391 set_bit(KEY_LEFT, input_dev->keybit);
392 set_bit(KEY_DOWN, input_dev->keybit);
393 set_bit(KEY_ENTER, input_dev->keybit);
394 set_bit(KEY_SUSPEND, input_dev->keybit);
395 set_bit(BTN_TOUCH, input_dev->keybit);
391 396
392 /* Device specific stuff */ 397 /* Device specific stuff */
393 set_GPIO_IRQ_edge(GPIO_BITSY_ACTION_BUTTON, GPIO_BOTH_EDGES); 398 set_GPIO_IRQ_edge(GPIO_BITSY_ACTION_BUTTON, GPIO_BOTH_EDGES);
@@ -397,73 +402,35 @@ static int h3600ts_connect(struct serio *serio, struct serio_driver *drv)
397 SA_SHIRQ | SA_INTERRUPT | SA_SAMPLE_RANDOM, 402 SA_SHIRQ | SA_INTERRUPT | SA_SAMPLE_RANDOM,
398 "h3600_action", &ts->dev)) { 403 "h3600_action", &ts->dev)) {
399 printk(KERN_ERR "h3600ts.c: Could not allocate Action Button IRQ!\n"); 404 printk(KERN_ERR "h3600ts.c: Could not allocate Action Button IRQ!\n");
400 kfree(ts); 405 err = -EBUSY;
401 return -EBUSY; 406 goto fail2;
402 } 407 }
403 408
404 if (request_irq(IRQ_GPIO_BITSY_NPOWER_BUTTON, npower_button_handler, 409 if (request_irq(IRQ_GPIO_BITSY_NPOWER_BUTTON, npower_button_handler,
405 SA_SHIRQ | SA_INTERRUPT | SA_SAMPLE_RANDOM, 410 SA_SHIRQ | SA_INTERRUPT | SA_SAMPLE_RANDOM,
406 "h3600_suspend", &ts->dev)) { 411 "h3600_suspend", &ts->dev)) {
407 free_irq(IRQ_GPIO_BITSY_ACTION_BUTTON, &ts->dev);
408 printk(KERN_ERR "h3600ts.c: Could not allocate Power Button IRQ!\n"); 412 printk(KERN_ERR "h3600ts.c: Could not allocate Power Button IRQ!\n");
409 kfree(ts); 413 err = -EBUSY;
410 return -EBUSY; 414 goto fail3;
411 } 415 }
412 416
413 /* Now we have things going we setup our input device */
414 ts->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_LED) | BIT(EV_PWR);
415 ts->dev.ledbit[0] = BIT(LED_SLEEP);
416 input_set_abs_params(&ts->dev, ABS_X, 60, 985, 0, 0);
417 input_set_abs_params(&ts->dev, ABS_Y, 35, 1024, 0, 0);
418
419 set_bit(KEY_RECORD, ts->dev.keybit);
420 set_bit(KEY_Q, ts->dev.keybit);
421 set_bit(KEY_PROG1, ts->dev.keybit);
422 set_bit(KEY_PROG2, ts->dev.keybit);
423 set_bit(KEY_PROG3, ts->dev.keybit);
424 set_bit(KEY_UP, ts->dev.keybit);
425 set_bit(KEY_RIGHT, ts->dev.keybit);
426 set_bit(KEY_LEFT, ts->dev.keybit);
427 set_bit(KEY_DOWN, ts->dev.keybit);
428 set_bit(KEY_ENTER, ts->dev.keybit);
429 ts->dev.keybit[LONG(BTN_TOUCH)] |= BIT(BTN_TOUCH);
430 ts->dev.keybit[LONG(KEY_SUSPEND)] |= BIT(KEY_SUSPEND);
431
432 ts->serio = serio;
433
434 sprintf(ts->phys, "%s/input0", serio->phys);
435
436 ts->dev.event = h3600ts_event;
437 ts->dev.private = ts;
438 ts->dev.name = h3600_name;
439 ts->dev.phys = ts->phys;
440 ts->dev.id.bustype = BUS_RS232;
441 ts->dev.id.vendor = SERIO_H3600;
442 ts->dev.id.product = 0x0666; /* FIXME !!! We can ask the hardware */
443 ts->dev.id.version = 0x0100;
444
445 serio_set_drvdata(serio, ts); 417 serio_set_drvdata(serio, ts);
446 418
447 err = serio_open(serio, drv); 419 err = serio_open(serio, drv);
448 if (err) { 420 if (err)
449 free_irq(IRQ_GPIO_BITSY_ACTION_BUTTON, ts);
450 free_irq(IRQ_GPIO_BITSY_NPOWER_BUTTON, ts);
451 serio_set_drvdata(serio, NULL);
452 kfree(ts);
453 return err; 421 return err;
454 }
455 422
456 //h3600_flite_control(1, 25); /* default brightness */ 423 //h3600_flite_control(1, 25); /* default brightness */
457#ifdef CONFIG_PM 424 input_register_device(ts->dev);
458 ts->pm_dev = pm_register(PM_ILLUMINATION_DEV, PM_SYS_LIGHT,
459 h3600ts_pm_callback);
460 printk("registered pm callback\n");
461#endif
462 input_register_device(&ts->dev);
463
464 printk(KERN_INFO "input: %s on %s\n", h3600_name, serio->phys);
465 425
466 return 0; 426 return 0;
427
428fail3: free_irq(IRQ_GPIO_BITSY_NPOWER_BUTTON, ts->dev);
429fail2: free_irq(IRQ_GPIO_BITSY_ACTION_BUTTON, ts->dev);
430fail1: serio_set_drvdata(serio, NULL);
431 input_free_device(input_dev);
432 kfree(ts);
433 return err;
467} 434}
468 435
469/* 436/*
@@ -476,9 +443,11 @@ static void h3600ts_disconnect(struct serio *serio)
476 443
477 free_irq(IRQ_GPIO_BITSY_ACTION_BUTTON, &ts->dev); 444 free_irq(IRQ_GPIO_BITSY_ACTION_BUTTON, &ts->dev);
478 free_irq(IRQ_GPIO_BITSY_NPOWER_BUTTON, &ts->dev); 445 free_irq(IRQ_GPIO_BITSY_NPOWER_BUTTON, &ts->dev);
479 input_unregister_device(&ts->dev); 446 input_get_device(ts->dev);
447 input_unregister_device(ts->dev);
480 serio_close(serio); 448 serio_close(serio);
481 serio_set_drvdata(serio, NULL); 449 serio_set_drvdata(serio, NULL);
450 input_put_device(ts->dev);
482 kfree(ts); 451 kfree(ts);
483} 452}
484 453
diff --git a/drivers/input/touchscreen/hp680_ts_input.c b/drivers/input/touchscreen/hp680_ts_input.c
index 7e1404441eca..957dd5a1b15e 100644
--- a/drivers/input/touchscreen/hp680_ts_input.c
+++ b/drivers/input/touchscreen/hp680_ts_input.c
@@ -21,10 +21,8 @@
21 21
22static void do_softint(void *data); 22static void do_softint(void *data);
23 23
24static struct input_dev hp680_ts_dev; 24static struct input_dev *hp680_ts_dev;
25static DECLARE_WORK(work, do_softint, 0); 25static DECLARE_WORK(work, do_softint, 0);
26static char *hp680_ts_name = "HP Jornada touchscreen";
27static char *hp680_ts_phys = "input0";
28 26
29static void do_softint(void *data) 27static void do_softint(void *data)
30{ 28{
@@ -58,14 +56,14 @@ static void do_softint(void *data)
58 } 56 }
59 57
60 if (touched) { 58 if (touched) {
61 input_report_key(&hp680_ts_dev, BTN_TOUCH, 1); 59 input_report_key(hp680_ts_dev, BTN_TOUCH, 1);
62 input_report_abs(&hp680_ts_dev, ABS_X, absx); 60 input_report_abs(hp680_ts_dev, ABS_X, absx);
63 input_report_abs(&hp680_ts_dev, ABS_Y, absy); 61 input_report_abs(hp680_ts_dev, ABS_Y, absy);
64 } else { 62 } else {
65 input_report_key(&hp680_ts_dev, BTN_TOUCH, 0); 63 input_report_key(hp680_ts_dev, BTN_TOUCH, 0);
66 } 64 }
67 65
68 input_sync(&hp680_ts_dev); 66 input_sync(hp680_ts_dev);
69 enable_irq(HP680_TS_IRQ); 67 enable_irq(HP680_TS_IRQ);
70} 68}
71 69
@@ -92,27 +90,29 @@ static int __init hp680_ts_init(void)
92 scpcr |= SCPCR_TS_ENABLE; 90 scpcr |= SCPCR_TS_ENABLE;
93 ctrl_outw(scpcr, SCPCR); 91 ctrl_outw(scpcr, SCPCR);
94 92
95 memset(&hp680_ts_dev, 0, sizeof(hp680_ts_dev)); 93 hp680_ts_dev = input_allocate_device();
96 init_input_dev(&hp680_ts_dev); 94 if (!hp680_ts_dev)
95 return -ENOMEM;
97 96
98 hp680_ts_dev.evbit[0] = BIT(EV_ABS) | BIT(EV_KEY); 97 hp680_ts_dev->evbit[0] = BIT(EV_ABS) | BIT(EV_KEY);
99 hp680_ts_dev.absbit[0] = BIT(ABS_X) | BIT(ABS_Y); 98 hp680_ts_dev->absbit[0] = BIT(ABS_X) | BIT(ABS_Y);
100 hp680_ts_dev.keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH); 99 hp680_ts_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
101 100
102 hp680_ts_dev.absmin[ABS_X] = HP680_TS_ABS_X_MIN; 101 hp680_ts_dev->absmin[ABS_X] = HP680_TS_ABS_X_MIN;
103 hp680_ts_dev.absmin[ABS_Y] = HP680_TS_ABS_Y_MIN; 102 hp680_ts_dev->absmin[ABS_Y] = HP680_TS_ABS_Y_MIN;
104 hp680_ts_dev.absmax[ABS_X] = HP680_TS_ABS_X_MAX; 103 hp680_ts_dev->absmax[ABS_X] = HP680_TS_ABS_X_MAX;
105 hp680_ts_dev.absmax[ABS_Y] = HP680_TS_ABS_Y_MAX; 104 hp680_ts_dev->absmax[ABS_Y] = HP680_TS_ABS_Y_MAX;
106 105
107 hp680_ts_dev.name = hp680_ts_name; 106 hp680_ts_dev->name = "HP Jornada touchscreen";
108 hp680_ts_dev.phys = hp680_ts_phys; 107 hp680_ts_dev->phys = "hp680_ts/input0";
109 input_register_device(&hp680_ts_dev);
110 108
111 if (request_irq 109 input_register_device(hp680_ts_dev);
112 (HP680_TS_IRQ, hp680_ts_interrupt, SA_INTERRUPT, MODNAME, 0) < 0) { 110
113 printk(KERN_ERR "hp680_touchscreen.c : Can't allocate irq %d\n", 111 if (request_irq(HP680_TS_IRQ, hp680_ts_interrupt,
112 SA_INTERRUPT, MODNAME, 0) < 0) {
113 printk(KERN_ERR "hp680_touchscreen.c: Can't allocate irq %d\n",
114 HP680_TS_IRQ); 114 HP680_TS_IRQ);
115 input_unregister_device(&hp680_ts_dev); 115 input_unregister_device(hp680_ts_dev);
116 return -EBUSY; 116 return -EBUSY;
117 } 117 }
118 118
@@ -124,7 +124,7 @@ static void __exit hp680_ts_exit(void)
124 free_irq(HP680_TS_IRQ, 0); 124 free_irq(HP680_TS_IRQ, 0);
125 cancel_delayed_work(&work); 125 cancel_delayed_work(&work);
126 flush_scheduled_work(); 126 flush_scheduled_work();
127 input_unregister_device(&hp680_ts_dev); 127 input_unregister_device(hp680_ts_dev);
128} 128}
129 129
130module_init(hp680_ts_init); 130module_init(hp680_ts_init);
diff --git a/drivers/input/touchscreen/mk712.c b/drivers/input/touchscreen/mk712.c
index afaaebe5225b..4844d250a5eb 100644
--- a/drivers/input/touchscreen/mk712.c
+++ b/drivers/input/touchscreen/mk712.c
@@ -77,7 +77,7 @@ MODULE_PARM_DESC(irq, "IRQ of MK712 touchscreen controller");
77#define MK712_READ_ONE_POINT 0x20 77#define MK712_READ_ONE_POINT 0x20
78#define MK712_POWERUP 0x40 78#define MK712_POWERUP 0x40
79 79
80static struct input_dev mk712_dev; 80static struct input_dev *mk712_dev;
81static DEFINE_SPINLOCK(mk712_lock); 81static DEFINE_SPINLOCK(mk712_lock);
82 82
83static irqreturn_t mk712_interrupt(int irq, void *dev_id, struct pt_regs *regs) 83static irqreturn_t mk712_interrupt(int irq, void *dev_id, struct pt_regs *regs)
@@ -88,7 +88,7 @@ static irqreturn_t mk712_interrupt(int irq, void *dev_id, struct pt_regs *regs)
88 static unsigned short last_y; 88 static unsigned short last_y;
89 89
90 spin_lock(&mk712_lock); 90 spin_lock(&mk712_lock);
91 input_regs(&mk712_dev, regs); 91 input_regs(mk712_dev, regs);
92 92
93 status = inb(mk712_io + MK712_STATUS); 93 status = inb(mk712_io + MK712_STATUS);
94 94
@@ -100,7 +100,7 @@ static irqreturn_t mk712_interrupt(int irq, void *dev_id, struct pt_regs *regs)
100 if (~status & MK712_STATUS_TOUCH) 100 if (~status & MK712_STATUS_TOUCH)
101 { 101 {
102 debounce = 1; 102 debounce = 1;
103 input_report_key(&mk712_dev, BTN_TOUCH, 0); 103 input_report_key(mk712_dev, BTN_TOUCH, 0);
104 goto end; 104 goto end;
105 } 105 }
106 106
@@ -110,15 +110,15 @@ static irqreturn_t mk712_interrupt(int irq, void *dev_id, struct pt_regs *regs)
110 goto end; 110 goto end;
111 } 111 }
112 112
113 input_report_key(&mk712_dev, BTN_TOUCH, 1); 113 input_report_key(mk712_dev, BTN_TOUCH, 1);
114 input_report_abs(&mk712_dev, ABS_X, last_x); 114 input_report_abs(mk712_dev, ABS_X, last_x);
115 input_report_abs(&mk712_dev, ABS_Y, last_y); 115 input_report_abs(mk712_dev, ABS_Y, last_y);
116 116
117end: 117end:
118 118
119 last_x = inw(mk712_io + MK712_X) & 0x0fff; 119 last_x = inw(mk712_io + MK712_X) & 0x0fff;
120 last_y = inw(mk712_io + MK712_Y) & 0x0fff; 120 last_y = inw(mk712_io + MK712_Y) & 0x0fff;
121 input_sync(&mk712_dev); 121 input_sync(mk712_dev);
122 spin_unlock(&mk712_lock); 122 spin_unlock(&mk712_lock);
123 return IRQ_HANDLED; 123 return IRQ_HANDLED;
124} 124}
@@ -154,30 +154,11 @@ static void mk712_close(struct input_dev *dev)
154 spin_unlock_irqrestore(&mk712_lock, flags); 154 spin_unlock_irqrestore(&mk712_lock, flags);
155} 155}
156 156
157static struct input_dev mk712_dev = {
158 .evbit = { BIT(EV_KEY) | BIT(EV_ABS) },
159 .keybit = { [LONG(BTN_TOUCH)] = BIT(BTN_TOUCH) },
160 .absbit = { BIT(ABS_X) | BIT(ABS_Y) },
161 .open = mk712_open,
162 .close = mk712_close,
163 .name = "ICS MicroClock MK712 TouchScreen",
164 .phys = "isa0260/input0",
165 .absmin = { [ABS_X] = 0, [ABS_Y] = 0 },
166 .absmax = { [ABS_X] = 0xfff, [ABS_Y] = 0xfff },
167 .absfuzz = { [ABS_X] = 88, [ABS_Y] = 88 },
168 .id = {
169 .bustype = BUS_ISA,
170 .vendor = 0x0005,
171 .product = 0x0001,
172 .version = 0x0100,
173 },
174};
175
176int __init mk712_init(void) 157int __init mk712_init(void)
177{ 158{
159 int err;
178 160
179 if(!request_region(mk712_io, 8, "mk712")) 161 if (!request_region(mk712_io, 8, "mk712")) {
180 {
181 printk(KERN_WARNING "mk712: unable to get IO region\n"); 162 printk(KERN_WARNING "mk712: unable to get IO region\n");
182 return -ENODEV; 163 return -ENODEV;
183 } 164 }
@@ -188,28 +169,49 @@ int __init mk712_init(void)
188 (inw(mk712_io + MK712_Y) & 0xf000) || 169 (inw(mk712_io + MK712_Y) & 0xf000) ||
189 (inw(mk712_io + MK712_STATUS) & 0xf333)) { 170 (inw(mk712_io + MK712_STATUS) & 0xf333)) {
190 printk(KERN_WARNING "mk712: device not present\n"); 171 printk(KERN_WARNING "mk712: device not present\n");
191 release_region(mk712_io, 8); 172 err = -ENODEV;
192 return -ENODEV; 173 goto fail;
193 } 174 }
194 175
195 if(request_irq(mk712_irq, mk712_interrupt, 0, "mk712", &mk712_dev)) 176 if (!(mk712_dev = input_allocate_device())) {
196 { 177 printk(KERN_ERR "mk712: not enough memory\n");
197 printk(KERN_WARNING "mk712: unable to get IRQ\n"); 178 err = -ENOMEM;
198 release_region(mk712_io, 8); 179 goto fail;
199 return -EBUSY;
200 } 180 }
201 181
202 input_register_device(&mk712_dev); 182 mk712_dev->name = "ICS MicroClock MK712 TouchScreen";
183 mk712_dev->phys = "isa0260/input0";
184 mk712_dev->id.bustype = BUS_ISA;
185 mk712_dev->id.vendor = 0x0005;
186 mk712_dev->id.product = 0x0001;
187 mk712_dev->id.version = 0x0100;
188
189 mk712_dev->open = mk712_open;
190 mk712_dev->close = mk712_close;
203 191
204 printk(KERN_INFO "input: ICS MicroClock MK712 TouchScreen at %#x irq %d\n", mk712_io, mk712_irq); 192 mk712_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
193 mk712_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
194 input_set_abs_params(mk712_dev, ABS_X, 0, 0xfff, 88, 0);
195 input_set_abs_params(mk712_dev, ABS_Y, 0, 0xfff, 88, 0);
205 196
197 if (request_irq(mk712_irq, mk712_interrupt, 0, "mk712", mk712_dev)) {
198 printk(KERN_WARNING "mk712: unable to get IRQ\n");
199 err = -EBUSY;
200 goto fail;
201 }
202
203 input_register_device(mk712_dev);
206 return 0; 204 return 0;
205
206 fail: input_free_device(mk712_dev);
207 release_region(mk712_io, 8);
208 return err;
207} 209}
208 210
209static void __exit mk712_exit(void) 211static void __exit mk712_exit(void)
210{ 212{
211 input_unregister_device(&mk712_dev); 213 input_unregister_device(mk712_dev);
212 free_irq(mk712_irq, &mk712_dev); 214 free_irq(mk712_irq, mk712_dev);
213 release_region(mk712_io, 8); 215 release_region(mk712_io, 8);
214} 216}
215 217
diff --git a/drivers/input/touchscreen/mtouch.c b/drivers/input/touchscreen/mtouch.c
index aa8ee7842179..1d0d37eeef6e 100644
--- a/drivers/input/touchscreen/mtouch.c
+++ b/drivers/input/touchscreen/mtouch.c
@@ -51,14 +51,12 @@ MODULE_LICENSE("GPL");
51#define MTOUCH_GET_YC(data) (((data[4])<<7) | data[3]) 51#define MTOUCH_GET_YC(data) (((data[4])<<7) | data[3])
52#define MTOUCH_GET_TOUCHED(data) (MTOUCH_FORMAT_TABLET_TOUCH_BIT & data[0]) 52#define MTOUCH_GET_TOUCHED(data) (MTOUCH_FORMAT_TABLET_TOUCH_BIT & data[0])
53 53
54static char *mtouch_name = "MicroTouch Serial TouchScreen";
55
56/* 54/*
57 * Per-touchscreen data. 55 * Per-touchscreen data.
58 */ 56 */
59 57
60struct mtouch { 58struct mtouch {
61 struct input_dev dev; 59 struct input_dev *dev;
62 struct serio *serio; 60 struct serio *serio;
63 int idx; 61 int idx;
64 unsigned char data[MTOUCH_MAX_LENGTH]; 62 unsigned char data[MTOUCH_MAX_LENGTH];
@@ -67,7 +65,7 @@ struct mtouch {
67 65
68static void mtouch_process_format_tablet(struct mtouch *mtouch, struct pt_regs *regs) 66static void mtouch_process_format_tablet(struct mtouch *mtouch, struct pt_regs *regs)
69{ 67{
70 struct input_dev *dev = &mtouch->dev; 68 struct input_dev *dev = mtouch->dev;
71 69
72 if (MTOUCH_FORMAT_TABLET_LENGTH == ++mtouch->idx) { 70 if (MTOUCH_FORMAT_TABLET_LENGTH == ++mtouch->idx) {
73 input_regs(dev, regs); 71 input_regs(dev, regs);
@@ -116,9 +114,11 @@ static void mtouch_disconnect(struct serio *serio)
116{ 114{
117 struct mtouch* mtouch = serio_get_drvdata(serio); 115 struct mtouch* mtouch = serio_get_drvdata(serio);
118 116
119 input_unregister_device(&mtouch->dev); 117 input_get_device(mtouch->dev);
118 input_unregister_device(mtouch->dev);
120 serio_close(serio); 119 serio_close(serio);
121 serio_set_drvdata(serio, NULL); 120 serio_set_drvdata(serio, NULL);
121 input_put_device(mtouch->dev);
122 kfree(mtouch); 122 kfree(mtouch);
123} 123}
124 124
@@ -131,46 +131,46 @@ static void mtouch_disconnect(struct serio *serio)
131static int mtouch_connect(struct serio *serio, struct serio_driver *drv) 131static int mtouch_connect(struct serio *serio, struct serio_driver *drv)
132{ 132{
133 struct mtouch *mtouch; 133 struct mtouch *mtouch;
134 struct input_dev *input_dev;
134 int err; 135 int err;
135 136
136 if (!(mtouch = kmalloc(sizeof(*mtouch), GFP_KERNEL))) 137 mtouch = kzalloc(sizeof(struct mtouch), GFP_KERNEL);
137 return -ENOMEM; 138 input_dev = input_allocate_device();
138 139 if (!mtouch || !input_dev) {
139 memset(mtouch, 0, sizeof(*mtouch)); 140 err = -ENOMEM;
140 141 goto fail;
141 init_input_dev(&mtouch->dev); 142 }
142 mtouch->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
143 mtouch->dev.keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
144
145 input_set_abs_params(&mtouch->dev, ABS_X, MTOUCH_MIN_XC, MTOUCH_MAX_XC, 0, 0);
146 input_set_abs_params(&mtouch->dev, ABS_Y, MTOUCH_MIN_YC, MTOUCH_MAX_YC, 0, 0);
147 143
148 mtouch->serio = serio; 144 mtouch->serio = serio;
149 145 mtouch->dev = input_dev;
150 sprintf(mtouch->phys, "%s/input0", serio->phys); 146 sprintf(mtouch->phys, "%s/input0", serio->phys);
151 147
152 mtouch->dev.private = mtouch; 148 input_dev->private = mtouch;
153 mtouch->dev.name = mtouch_name; 149 input_dev->name = "MicroTouch Serial TouchScreen";
154 mtouch->dev.phys = mtouch->phys; 150 input_dev->phys = mtouch->phys;
155 mtouch->dev.id.bustype = BUS_RS232; 151 input_dev->id.bustype = BUS_RS232;
156 mtouch->dev.id.vendor = SERIO_MICROTOUCH; 152 input_dev->id.vendor = SERIO_MICROTOUCH;
157 mtouch->dev.id.product = 0; 153 input_dev->id.product = 0;
158 mtouch->dev.id.version = 0x0100; 154 input_dev->id.version = 0x0100;
155 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
156 input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
157 input_set_abs_params(mtouch->dev, ABS_X, MTOUCH_MIN_XC, MTOUCH_MAX_XC, 0, 0);
158 input_set_abs_params(mtouch->dev, ABS_Y, MTOUCH_MIN_YC, MTOUCH_MAX_YC, 0, 0);
159 159
160 serio_set_drvdata(serio, mtouch); 160 serio_set_drvdata(serio, mtouch);
161 161
162 err = serio_open(serio, drv); 162 err = serio_open(serio, drv);
163 if (err) { 163 if (err)
164 serio_set_drvdata(serio, NULL); 164 goto fail;
165 kfree(mtouch);
166 return err;
167 }
168
169 input_register_device(&mtouch->dev);
170 165
171 printk(KERN_INFO "input: %s on %s\n", mtouch->dev.name, serio->phys); 166 input_register_device(mtouch->dev);
172 167
173 return 0; 168 return 0;
169
170 fail: serio_set_drvdata(serio, NULL);
171 input_free_device(input_dev);
172 kfree(mtouch);
173 return err;
174} 174}
175 175
176/* 176/*
diff --git a/drivers/input/tsdev.c b/drivers/input/tsdev.c
index 50c63a155156..ca1547929d62 100644
--- a/drivers/input/tsdev.c
+++ b/drivers/input/tsdev.c
@@ -53,7 +53,6 @@
53#include <linux/random.h> 53#include <linux/random.h>
54#include <linux/time.h> 54#include <linux/time.h>
55#include <linux/device.h> 55#include <linux/device.h>
56#include <linux/devfs_fs_kernel.h>
57 56
58#ifndef CONFIG_INPUT_TSDEV_SCREEN_X 57#ifndef CONFIG_INPUT_TSDEV_SCREEN_X
59#define CONFIG_INPUT_TSDEV_SCREEN_X 240 58#define CONFIG_INPUT_TSDEV_SCREEN_X 240
@@ -369,6 +368,7 @@ static struct input_handle *tsdev_connect(struct input_handler *handler,
369 struct input_device_id *id) 368 struct input_device_id *id)
370{ 369{
371 struct tsdev *tsdev; 370 struct tsdev *tsdev;
371 struct class_device *cdev;
372 int minor, delta; 372 int minor, delta;
373 373
374 for (minor = 0; minor < TSDEV_MINORS/2 && tsdev_table[minor]; 374 for (minor = 0; minor < TSDEV_MINORS/2 && tsdev_table[minor];
@@ -410,13 +410,13 @@ static struct input_handle *tsdev_connect(struct input_handler *handler,
410 410
411 tsdev_table[minor] = tsdev; 411 tsdev_table[minor] = tsdev;
412 412
413 devfs_mk_cdev(MKDEV(INPUT_MAJOR, TSDEV_MINOR_BASE + minor), 413 cdev = class_device_create(&input_class, &dev->cdev,
414 S_IFCHR|S_IRUGO|S_IWUSR, "input/ts%d", minor);
415 devfs_mk_cdev(MKDEV(INPUT_MAJOR, TSDEV_MINOR_BASE + minor + TSDEV_MINORS/2),
416 S_IFCHR|S_IRUGO|S_IWUSR, "input/tsraw%d", minor);
417 class_device_create(input_class,
418 MKDEV(INPUT_MAJOR, TSDEV_MINOR_BASE + minor), 414 MKDEV(INPUT_MAJOR, TSDEV_MINOR_BASE + minor),
419 dev->dev, "ts%d", minor); 415 dev->cdev.dev, tsdev->name);
416
417 /* temporary symlink to keep userspace happy */
418 sysfs_create_link(&input_class.subsys.kset.kobj, &cdev->kobj,
419 tsdev->name);
420 420
421 return &tsdev->handle; 421 return &tsdev->handle;
422} 422}
@@ -426,10 +426,9 @@ static void tsdev_disconnect(struct input_handle *handle)
426 struct tsdev *tsdev = handle->private; 426 struct tsdev *tsdev = handle->private;
427 struct tsdev_list *list; 427 struct tsdev_list *list;
428 428
429 class_device_destroy(input_class, 429 sysfs_remove_link(&input_class.subsys.kset.kobj, tsdev->name);
430 class_device_destroy(&input_class,
430 MKDEV(INPUT_MAJOR, TSDEV_MINOR_BASE + tsdev->minor)); 431 MKDEV(INPUT_MAJOR, TSDEV_MINOR_BASE + tsdev->minor));
431 devfs_remove("input/ts%d", tsdev->minor);
432 devfs_remove("input/tsraw%d", tsdev->minor);
433 tsdev->exist = 0; 432 tsdev->exist = 0;
434 433
435 if (tsdev->open) { 434 if (tsdev->open) {