aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/input')
-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
25 files changed, 1460 insertions, 1230 deletions
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/*