diff options
Diffstat (limited to 'drivers/input/joystick')
27 files changed, 1472 insertions, 1230 deletions
diff --git a/drivers/input/joystick/a3d.c b/drivers/input/joystick/a3d.c index bf65430181fa..4571ea3a4b92 100644 --- a/drivers/input/joystick/a3d.c +++ b/drivers/input/joystick/a3d.c | |||
@@ -34,6 +34,7 @@ | |||
34 | #include <linux/init.h> | 34 | #include <linux/init.h> |
35 | #include <linux/gameport.h> | 35 | #include <linux/gameport.h> |
36 | #include <linux/input.h> | 36 | #include <linux/input.h> |
37 | #include <linux/jiffies.h> | ||
37 | 38 | ||
38 | #define DRIVER_DESC "FP-Gaming Assasin 3D joystick driver" | 39 | #define DRIVER_DESC "FP-Gaming Assasin 3D joystick driver" |
39 | 40 | ||
diff --git a/drivers/input/joystick/adi.c b/drivers/input/joystick/adi.c index cf35ae638a0d..704bf70f1db7 100644 --- a/drivers/input/joystick/adi.c +++ b/drivers/input/joystick/adi.c | |||
@@ -34,6 +34,7 @@ | |||
34 | #include <linux/input.h> | 34 | #include <linux/input.h> |
35 | #include <linux/gameport.h> | 35 | #include <linux/gameport.h> |
36 | #include <linux/init.h> | 36 | #include <linux/init.h> |
37 | #include <linux/jiffies.h> | ||
37 | 38 | ||
38 | #define DRIVER_DESC "Logitech ADI joystick family driver" | 39 | #define DRIVER_DESC "Logitech ADI joystick family driver" |
39 | 40 | ||
@@ -54,7 +55,7 @@ MODULE_LICENSE("GPL"); | |||
54 | #define ADI_MIN_LENGTH 8 | 55 | #define ADI_MIN_LENGTH 8 |
55 | #define ADI_MIN_LEN_LENGTH 10 | 56 | #define ADI_MIN_LEN_LENGTH 10 |
56 | #define ADI_MIN_ID_LENGTH 66 | 57 | #define ADI_MIN_ID_LENGTH 66 |
57 | #define ADI_MAX_NAME_LENGTH 48 | 58 | #define ADI_MAX_NAME_LENGTH 64 |
58 | #define ADI_MAX_CNAME_LENGTH 16 | 59 | #define ADI_MAX_CNAME_LENGTH 16 |
59 | #define ADI_MAX_PHYS_LENGTH 64 | 60 | #define ADI_MAX_PHYS_LENGTH 64 |
60 | 61 | ||
@@ -106,7 +107,7 @@ static struct { | |||
106 | */ | 107 | */ |
107 | 108 | ||
108 | struct adi { | 109 | struct adi { |
109 | struct input_dev dev; | 110 | struct input_dev *dev; |
110 | int length; | 111 | int length; |
111 | int ret; | 112 | int ret; |
112 | int idx; | 113 | int idx; |
@@ -215,7 +216,7 @@ static inline int adi_get_bits(struct adi *adi, int count) | |||
215 | 216 | ||
216 | static int adi_decode(struct adi *adi) | 217 | static int adi_decode(struct adi *adi) |
217 | { | 218 | { |
218 | struct input_dev *dev = &adi->dev; | 219 | struct input_dev *dev = adi->dev; |
219 | char *abs = adi->abs; | 220 | char *abs = adi->abs; |
220 | short *key = adi->key; | 221 | short *key = adi->key; |
221 | int i, t; | 222 | int i, t; |
@@ -318,7 +319,8 @@ static void adi_init_digital(struct gameport *gameport) | |||
318 | 319 | ||
319 | for (i = 0; seq[i]; i++) { | 320 | for (i = 0; seq[i]; i++) { |
320 | gameport_trigger(gameport); | 321 | gameport_trigger(gameport); |
321 | if (seq[i] > 0) msleep(seq[i]); | 322 | if (seq[i] > 0) |
323 | msleep(seq[i]); | ||
322 | if (seq[i] < 0) { | 324 | if (seq[i] < 0) { |
323 | mdelay(-seq[i]); | 325 | mdelay(-seq[i]); |
324 | udelay(-seq[i]*14); /* It looks like mdelay() is off by approx 1.4% */ | 326 | udelay(-seq[i]*14); /* It looks like mdelay() is off by approx 1.4% */ |
@@ -397,42 +399,46 @@ static void adi_id_decode(struct adi *adi, struct adi_port *port) | |||
397 | } | 399 | } |
398 | } | 400 | } |
399 | 401 | ||
400 | static void adi_init_input(struct adi *adi, struct adi_port *port, int half) | 402 | static int adi_init_input(struct adi *adi, struct adi_port *port, int half) |
401 | { | 403 | { |
402 | int i, t; | 404 | struct input_dev *input_dev; |
403 | char buf[ADI_MAX_NAME_LENGTH]; | 405 | char buf[ADI_MAX_NAME_LENGTH]; |
406 | int i, t; | ||
404 | 407 | ||
405 | if (!adi->length) return; | 408 | adi->dev = input_dev = input_allocate_device(); |
406 | 409 | if (!input_dev) | |
407 | init_input_dev(&adi->dev); | 410 | return -ENOMEM; |
408 | 411 | ||
409 | t = adi->id < ADI_ID_MAX ? adi->id : ADI_ID_MAX; | 412 | t = adi->id < ADI_ID_MAX ? adi->id : ADI_ID_MAX; |
410 | 413 | ||
411 | snprintf(buf, ADI_MAX_PHYS_LENGTH, adi_names[t], adi->id); | 414 | snprintf(buf, ADI_MAX_PHYS_LENGTH, adi_names[t], adi->id); |
412 | snprintf(adi->name, ADI_MAX_NAME_LENGTH, "Logitech %s", buf); | 415 | 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); | 416 | snprintf(adi->phys, ADI_MAX_PHYS_LENGTH, "%s/input%d", port->gameport->phys, half); |
414 | 417 | ||
415 | adi->abs = adi_abs[t]; | 418 | adi->abs = adi_abs[t]; |
416 | adi->key = adi_key[t]; | 419 | adi->key = adi_key[t]; |
417 | 420 | ||
418 | adi->dev.open = adi_open; | 421 | input_dev->name = adi->name; |
419 | adi->dev.close = adi_close; | 422 | input_dev->phys = adi->phys; |
423 | input_dev->id.bustype = BUS_GAMEPORT; | ||
424 | input_dev->id.vendor = GAMEPORT_ID_VENDOR_LOGITECH; | ||
425 | input_dev->id.product = adi->id; | ||
426 | input_dev->id.version = 0x0100; | ||
427 | input_dev->cdev.dev = &port->gameport->dev; | ||
428 | input_dev->private = port; | ||
420 | 429 | ||
421 | adi->dev.name = adi->name; | 430 | input_dev->open = adi_open; |
422 | adi->dev.phys = adi->phys; | 431 | 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 | 432 | ||
428 | adi->dev.private = port; | 433 | input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); |
429 | adi->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); | ||
430 | 434 | ||
431 | for (i = 0; i < adi->axes10 + adi->axes8 + (adi->hats + (adi->pad != -1)) * 2; i++) | 435 | for (i = 0; i < adi->axes10 + adi->axes8 + (adi->hats + (adi->pad != -1)) * 2; i++) |
432 | set_bit(adi->abs[i], adi->dev.absbit); | 436 | set_bit(adi->abs[i], input_dev->absbit); |
433 | 437 | ||
434 | for (i = 0; i < adi->buttons; i++) | 438 | for (i = 0; i < adi->buttons; i++) |
435 | set_bit(adi->key[i], adi->dev.keybit); | 439 | set_bit(adi->key[i], input_dev->keybit); |
440 | |||
441 | return 0; | ||
436 | } | 442 | } |
437 | 443 | ||
438 | static void adi_init_center(struct adi *adi) | 444 | static void adi_init_center(struct adi *adi) |
@@ -445,17 +451,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++) { | 451 | for (i = 0; i < adi->axes10 + adi->axes8 + (adi->hats + (adi->pad != -1)) * 2; i++) { |
446 | 452 | ||
447 | t = adi->abs[i]; | 453 | t = adi->abs[i]; |
448 | x = adi->dev.abs[t]; | 454 | x = adi->dev->abs[t]; |
449 | 455 | ||
450 | if (t == ABS_THROTTLE || t == ABS_RUDDER || adi->id == ADI_ID_WGPE) | 456 | if (t == ABS_THROTTLE || t == ABS_RUDDER || adi->id == ADI_ID_WGPE) |
451 | x = i < adi->axes10 ? 512 : 128; | 457 | x = i < adi->axes10 ? 512 : 128; |
452 | 458 | ||
453 | if (i < adi->axes10) | 459 | if (i < adi->axes10) |
454 | input_set_abs_params(&adi->dev, t, 64, x * 2 - 64, 2, 16); | 460 | input_set_abs_params(adi->dev, t, 64, x * 2 - 64, 2, 16); |
455 | else if (i < adi->axes10 + adi->axes8) | 461 | else if (i < adi->axes10 + adi->axes8) |
456 | input_set_abs_params(&adi->dev, t, 48, x * 2 - 48, 1, 16); | 462 | input_set_abs_params(adi->dev, t, 48, x * 2 - 48, 1, 16); |
457 | else | 463 | else |
458 | input_set_abs_params(&adi->dev, t, -1, 1, 0, 0); | 464 | input_set_abs_params(adi->dev, t, -1, 1, 0, 0); |
459 | } | 465 | } |
460 | } | 466 | } |
461 | 467 | ||
@@ -469,7 +475,8 @@ static int adi_connect(struct gameport *gameport, struct gameport_driver *drv) | |||
469 | int i; | 475 | int i; |
470 | int err; | 476 | int err; |
471 | 477 | ||
472 | if (!(port = kzalloc(sizeof(struct adi_port), GFP_KERNEL))) | 478 | port = kzalloc(sizeof(struct adi_port), GFP_KERNEL); |
479 | if (!port) | ||
473 | return -ENOMEM; | 480 | return -ENOMEM; |
474 | 481 | ||
475 | port->gameport = gameport; | 482 | port->gameport = gameport; |
@@ -477,10 +484,8 @@ static int adi_connect(struct gameport *gameport, struct gameport_driver *drv) | |||
477 | gameport_set_drvdata(gameport, port); | 484 | gameport_set_drvdata(gameport, port); |
478 | 485 | ||
479 | err = gameport_open(gameport, drv, GAMEPORT_MODE_RAW); | 486 | err = gameport_open(gameport, drv, GAMEPORT_MODE_RAW); |
480 | if (err) { | 487 | if (err) |
481 | kfree(port); | 488 | goto fail1; |
482 | return err; | ||
483 | } | ||
484 | 489 | ||
485 | adi_init_digital(gameport); | 490 | adi_init_digital(gameport); |
486 | adi_read_packet(port); | 491 | adi_read_packet(port); |
@@ -490,13 +495,18 @@ static int adi_connect(struct gameport *gameport, struct gameport_driver *drv) | |||
490 | 495 | ||
491 | for (i = 0; i < 2; i++) { | 496 | for (i = 0; i < 2; i++) { |
492 | adi_id_decode(port->adi + i, port); | 497 | adi_id_decode(port->adi + i, port); |
493 | adi_init_input(port->adi + i, port, i); | 498 | |
499 | if (!port->adi[i].length) | ||
500 | continue; | ||
501 | |||
502 | err = adi_init_input(port->adi + i, port, i); | ||
503 | if (err) | ||
504 | goto fail2; | ||
494 | } | 505 | } |
495 | 506 | ||
496 | if (!port->adi[0].length && !port->adi[1].length) { | 507 | if (!port->adi[0].length && !port->adi[1].length) { |
497 | gameport_close(gameport); | 508 | err = -ENODEV; |
498 | kfree(port); | 509 | goto fail2; |
499 | return -ENODEV; | ||
500 | } | 510 | } |
501 | 511 | ||
502 | gameport_set_poll_handler(gameport, adi_poll); | 512 | gameport_set_poll_handler(gameport, adi_poll); |
@@ -511,12 +521,18 @@ static int adi_connect(struct gameport *gameport, struct gameport_driver *drv) | |||
511 | for (i = 0; i < 2; i++) | 521 | for (i = 0; i < 2; i++) |
512 | if (port->adi[i].length > 0) { | 522 | if (port->adi[i].length > 0) { |
513 | adi_init_center(port->adi + i); | 523 | adi_init_center(port->adi + i); |
514 | input_register_device(&port->adi[i].dev); | 524 | 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 | } | 525 | } |
518 | 526 | ||
519 | return 0; | 527 | return 0; |
528 | |||
529 | fail2: for (i = 0; i < 2; i++) | ||
530 | if (port->adi[i].dev) | ||
531 | input_free_device(port->adi[i].dev); | ||
532 | gameport_close(gameport); | ||
533 | fail1: gameport_set_drvdata(gameport, NULL); | ||
534 | kfree(port); | ||
535 | return err; | ||
520 | } | 536 | } |
521 | 537 | ||
522 | static void adi_disconnect(struct gameport *gameport) | 538 | static void adi_disconnect(struct gameport *gameport) |
@@ -526,7 +542,7 @@ static void adi_disconnect(struct gameport *gameport) | |||
526 | 542 | ||
527 | for (i = 0; i < 2; i++) | 543 | for (i = 0; i < 2; i++) |
528 | if (port->adi[i].length > 0) | 544 | if (port->adi[i].length > 0) |
529 | input_unregister_device(&port->adi[i].dev); | 545 | input_unregister_device(port->adi[i].dev); |
530 | gameport_close(gameport); | 546 | gameport_close(gameport); |
531 | gameport_set_drvdata(gameport, NULL); | 547 | gameport_set_drvdata(gameport, NULL); |
532 | kfree(port); | 548 | 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 | ||
54 | static int amijoy_used; | 54 | static int amijoy_used; |
55 | static DECLARE_MUTEX(amijoy_sem); | 55 | static DECLARE_MUTEX(amijoy_sem); |
56 | static struct input_dev amijoy_dev[2]; | 56 | static struct input_dev *amijoy_dev[2]; |
57 | static char *amijoy_phys[2] = { "amijoy/input0", "amijoy/input1" }; | 57 | static char *amijoy_phys[2] = { "amijoy/input0", "amijoy/input1" }; |
58 | 58 | ||
59 | static char *amijoy_name = "Amiga joystick"; | ||
60 | |||
61 | static irqreturn_t amijoy_interrupt(int irq, void *dummy, struct pt_regs *fp) | 59 | static 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) | |||
114 | static int __init amijoy_init(void) | 112 | static 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 | ||
152 | static void __exit amijoy_exit(void) | 163 | static 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..3121961e3e7c 100644 --- a/drivers/input/joystick/analog.c +++ b/drivers/input/joystick/analog.c | |||
@@ -38,6 +38,7 @@ | |||
38 | #include <linux/init.h> | 38 | #include <linux/init.h> |
39 | #include <linux/input.h> | 39 | #include <linux/input.h> |
40 | #include <linux/gameport.h> | 40 | #include <linux/gameport.h> |
41 | #include <linux/jiffies.h> | ||
41 | #include <asm/timex.h> | 42 | #include <asm/timex.h> |
42 | 43 | ||
43 | #define DRIVER_DESC "Analog joystick and gamepad driver" | 44 | #define DRIVER_DESC "Analog joystick and gamepad driver" |
@@ -111,7 +112,7 @@ static short analog_joy_btn[] = { BTN_TRIGGER, BTN_THUMB, BTN_TOP, BTN_TOP2, BTN | |||
111 | static unsigned char analog_chf[] = { 0xf, 0x0, 0x1, 0x9, 0x2, 0x4, 0xc, 0x8, 0x3, 0x5, 0xb, 0x7, 0xd, 0xe, 0xa, 0x6 }; | 112 | static unsigned char analog_chf[] = { 0xf, 0x0, 0x1, 0x9, 0x2, 0x4, 0xc, 0x8, 0x3, 0x5, 0xb, 0x7, 0xd, 0xe, 0xa, 0x6 }; |
112 | 113 | ||
113 | struct analog { | 114 | struct analog { |
114 | struct input_dev dev; | 115 | struct input_dev *dev; |
115 | int mask; | 116 | int mask; |
116 | short *buttons; | 117 | short *buttons; |
117 | char name[ANALOG_MAX_NAME_LENGTH]; | 118 | char name[ANALOG_MAX_NAME_LENGTH]; |
@@ -182,7 +183,7 @@ static unsigned long analog_faketime = 0; | |||
182 | 183 | ||
183 | static void analog_decode(struct analog *analog, int *axes, int *initial, int buttons) | 184 | static void analog_decode(struct analog *analog, int *axes, int *initial, int buttons) |
184 | { | 185 | { |
185 | struct input_dev *dev = &analog->dev; | 186 | struct input_dev *dev = analog->dev; |
186 | int i, j; | 187 | int i, j; |
187 | 188 | ||
188 | if (analog->mask & ANALOG_HAT_FCS) | 189 | if (analog->mask & ANALOG_HAT_FCS) |
@@ -428,27 +429,30 @@ static void analog_name(struct analog *analog) | |||
428 | * analog_init_device() | 429 | * analog_init_device() |
429 | */ | 430 | */ |
430 | 431 | ||
431 | static void analog_init_device(struct analog_port *port, struct analog *analog, int index) | 432 | static int analog_init_device(struct analog_port *port, struct analog *analog, int index) |
432 | { | 433 | { |
434 | struct input_dev *input_dev; | ||
433 | int i, j, t, v, w, x, y, z; | 435 | int i, j, t, v, w, x, y, z; |
434 | 436 | ||
435 | analog_name(analog); | 437 | analog_name(analog); |
436 | sprintf(analog->phys, "%s/input%d", port->gameport->phys, index); | 438 | sprintf(analog->phys, "%s/input%d", port->gameport->phys, index); |
437 | analog->buttons = (analog->mask & ANALOG_GAMEPAD) ? analog_pad_btn : analog_joy_btn; | 439 | analog->buttons = (analog->mask & ANALOG_GAMEPAD) ? analog_pad_btn : analog_joy_btn; |
438 | 440 | ||
439 | init_input_dev(&analog->dev); | 441 | analog->dev = input_dev = input_allocate_device(); |
442 | if (!input_dev) | ||
443 | return -ENOMEM; | ||
440 | 444 | ||
441 | analog->dev.name = analog->name; | 445 | input_dev->name = analog->name; |
442 | analog->dev.phys = analog->phys; | 446 | input_dev->phys = analog->phys; |
443 | analog->dev.id.bustype = BUS_GAMEPORT; | 447 | input_dev->id.bustype = BUS_GAMEPORT; |
444 | analog->dev.id.vendor = GAMEPORT_ID_VENDOR_ANALOG; | 448 | input_dev->id.vendor = GAMEPORT_ID_VENDOR_ANALOG; |
445 | analog->dev.id.product = analog->mask >> 4; | 449 | input_dev->id.product = analog->mask >> 4; |
446 | analog->dev.id.version = 0x0100; | 450 | input_dev->id.version = 0x0100; |
447 | 451 | ||
448 | analog->dev.open = analog_open; | 452 | input_dev->open = analog_open; |
449 | analog->dev.close = analog_close; | 453 | input_dev->close = analog_close; |
450 | analog->dev.private = port; | 454 | input_dev->private = port; |
451 | analog->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); | 455 | input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); |
452 | 456 | ||
453 | for (i = j = 0; i < 4; i++) | 457 | for (i = j = 0; i < 4; i++) |
454 | if (analog->mask & (1 << i)) { | 458 | if (analog->mask & (1 << i)) { |
@@ -461,8 +465,6 @@ static void analog_init_device(struct analog_port *port, struct analog *analog, | |||
461 | v = (x >> 3); | 465 | v = (x >> 3); |
462 | w = (x >> 3); | 466 | w = (x >> 3); |
463 | 467 | ||
464 | set_bit(t, analog->dev.absbit); | ||
465 | |||
466 | if ((i == 2 || i == 3) && (j == 2 || j == 3) && (z > (y >> 3))) | 468 | if ((i == 2 || i == 3) && (j == 2 || j == 3) && (z > (y >> 3))) |
467 | x = y; | 469 | x = y; |
468 | 470 | ||
@@ -472,11 +474,7 @@ static void analog_init_device(struct analog_port *port, struct analog *analog, | |||
472 | w = (x >> 4); | 474 | w = (x >> 4); |
473 | } | 475 | } |
474 | 476 | ||
475 | analog->dev.absmax[t] = (x << 1) - v; | 477 | 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++; | 478 | j++; |
481 | } | 479 | } |
482 | 480 | ||
@@ -484,41 +482,30 @@ static void analog_init_device(struct analog_port *port, struct analog *analog, | |||
484 | if (analog->mask & analog_exts[i]) | 482 | if (analog->mask & analog_exts[i]) |
485 | for (x = 0; x < 2; x++) { | 483 | for (x = 0; x < 2; x++) { |
486 | t = analog_hats[j++]; | 484 | t = analog_hats[j++]; |
487 | set_bit(t, analog->dev.absbit); | 485 | input_set_abs_params(input_dev, t, -1, 1, 0, 0); |
488 | analog->dev.absmax[t] = 1; | ||
489 | analog->dev.absmin[t] = -1; | ||
490 | } | 486 | } |
491 | 487 | ||
492 | for (i = j = 0; i < 4; i++) | 488 | for (i = j = 0; i < 4; i++) |
493 | if (analog->mask & (0x10 << i)) | 489 | if (analog->mask & (0x10 << i)) |
494 | set_bit(analog->buttons[j++], analog->dev.keybit); | 490 | set_bit(analog->buttons[j++], input_dev->keybit); |
495 | 491 | ||
496 | if (analog->mask & ANALOG_BTNS_CHF) | 492 | if (analog->mask & ANALOG_BTNS_CHF) |
497 | for (i = 0; i < 2; i++) | 493 | for (i = 0; i < 2; i++) |
498 | set_bit(analog->buttons[j++], analog->dev.keybit); | 494 | set_bit(analog->buttons[j++], input_dev->keybit); |
499 | 495 | ||
500 | if (analog->mask & ANALOG_HBTN_CHF) | 496 | if (analog->mask & ANALOG_HBTN_CHF) |
501 | for (i = 0; i < 4; i++) | 497 | for (i = 0; i < 4; i++) |
502 | set_bit(analog->buttons[j++], analog->dev.keybit); | 498 | set_bit(analog->buttons[j++], input_dev->keybit); |
503 | 499 | ||
504 | for (i = 0; i < 4; i++) | 500 | for (i = 0; i < 4; i++) |
505 | if (analog->mask & (ANALOG_BTN_TL << i)) | 501 | if (analog->mask & (ANALOG_BTN_TL << i)) |
506 | set_bit(analog_pads[i], analog->dev.keybit); | 502 | set_bit(analog_pads[i], input_dev->keybit); |
507 | 503 | ||
508 | analog_decode(analog, port->axes, port->initial, port->buttons); | 504 | analog_decode(analog, port->axes, port->initial, port->buttons); |
509 | 505 | ||
510 | input_register_device(&analog->dev); | 506 | input_register_device(analog->dev); |
511 | 507 | ||
512 | printk(KERN_INFO "input: %s at %s", analog->name, port->gameport->phys); | 508 | 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 | } | 509 | } |
523 | 510 | ||
524 | /* | 511 | /* |
@@ -659,37 +646,41 @@ static int analog_connect(struct gameport *gameport, struct gameport_driver *drv | |||
659 | return - ENOMEM; | 646 | return - ENOMEM; |
660 | 647 | ||
661 | err = analog_init_port(gameport, drv, port); | 648 | err = analog_init_port(gameport, drv, port); |
662 | if (err) { | 649 | if (err) |
663 | kfree(port); | 650 | goto fail1; |
664 | return err; | ||
665 | } | ||
666 | 651 | ||
667 | err = analog_init_masks(port); | 652 | err = analog_init_masks(port); |
668 | if (err) { | 653 | if (err) |
669 | gameport_close(gameport); | 654 | goto fail2; |
670 | gameport_set_drvdata(gameport, NULL); | ||
671 | kfree(port); | ||
672 | return err; | ||
673 | } | ||
674 | 655 | ||
675 | gameport_set_poll_handler(gameport, analog_poll); | 656 | gameport_set_poll_handler(gameport, analog_poll); |
676 | gameport_set_poll_interval(gameport, 10); | 657 | gameport_set_poll_interval(gameport, 10); |
677 | 658 | ||
678 | for (i = 0; i < 2; i++) | 659 | for (i = 0; i < 2; i++) |
679 | if (port->analog[i].mask) | 660 | if (port->analog[i].mask) { |
680 | analog_init_device(port, port->analog + i, i); | 661 | err = analog_init_device(port, port->analog + i, i); |
662 | if (err) | ||
663 | goto fail3; | ||
664 | } | ||
681 | 665 | ||
682 | return 0; | 666 | return 0; |
667 | |||
668 | fail3: while (--i >= 0) | ||
669 | input_unregister_device(port->analog[i].dev); | ||
670 | fail2: gameport_close(gameport); | ||
671 | fail1: gameport_set_drvdata(gameport, NULL); | ||
672 | kfree(port); | ||
673 | return err; | ||
683 | } | 674 | } |
684 | 675 | ||
685 | static void analog_disconnect(struct gameport *gameport) | 676 | static void analog_disconnect(struct gameport *gameport) |
686 | { | 677 | { |
687 | int i; | ||
688 | struct analog_port *port = gameport_get_drvdata(gameport); | 678 | struct analog_port *port = gameport_get_drvdata(gameport); |
679 | int i; | ||
689 | 680 | ||
690 | for (i = 0; i < 2; i++) | 681 | for (i = 0; i < 2; i++) |
691 | if (port->analog[i].mask) | 682 | if (port->analog[i].mask) |
692 | input_unregister_device(&port->analog[i].dev); | 683 | input_unregister_device(port->analog[i].dev); |
693 | gameport_close(gameport); | 684 | gameport_close(gameport); |
694 | gameport_set_drvdata(gameport, NULL); | 685 | gameport_set_drvdata(gameport, NULL); |
695 | printk(KERN_INFO "analog.c: %d out of %d reads (%d%%) on %s failed\n", | 686 | 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..1909f7ef340c 100644 --- a/drivers/input/joystick/cobra.c +++ b/drivers/input/joystick/cobra.c | |||
@@ -34,6 +34,7 @@ | |||
34 | #include <linux/init.h> | 34 | #include <linux/init.h> |
35 | #include <linux/gameport.h> | 35 | #include <linux/gameport.h> |
36 | #include <linux/input.h> | 36 | #include <linux/input.h> |
37 | #include <linux/jiffies.h> | ||
37 | 38 | ||
38 | #define DRIVER_DESC "Creative Labs Blaster GamePad Cobra driver" | 39 | #define DRIVER_DESC "Creative Labs Blaster GamePad Cobra driver" |
39 | 40 | ||
@@ -44,13 +45,11 @@ MODULE_LICENSE("GPL"); | |||
44 | #define COBRA_MAX_STROBE 45 /* 45 us max wait for first strobe */ | 45 | #define COBRA_MAX_STROBE 45 /* 45 us max wait for first strobe */ |
45 | #define COBRA_LENGTH 36 | 46 | #define COBRA_LENGTH 36 |
46 | 47 | ||
47 | static char* cobra_name = "Creative Labs Blaster GamePad Cobra"; | ||
48 | |||
49 | static 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 }; | 48 | static 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 | 49 | ||
51 | struct cobra { | 50 | struct cobra { |
52 | struct gameport *gameport; | 51 | struct gameport *gameport; |
53 | struct input_dev dev[2]; | 52 | struct input_dev *dev[2]; |
54 | int reads; | 53 | int reads; |
55 | int bads; | 54 | int bads; |
56 | unsigned char exists; | 55 | unsigned char exists; |
@@ -128,7 +127,7 @@ static void cobra_poll(struct gameport *gameport) | |||
128 | for (i = 0; i < 2; i++) | 127 | for (i = 0; i < 2; i++) |
129 | if (cobra->exists & r & (1 << i)) { | 128 | if (cobra->exists & r & (1 << i)) { |
130 | 129 | ||
131 | dev = cobra->dev + i; | 130 | dev = cobra->dev[i]; |
132 | 131 | ||
133 | input_report_abs(dev, ABS_X, ((data[i] >> 4) & 1) - ((data[i] >> 3) & 1)); | 132 | 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)); | 133 | input_report_abs(dev, ABS_Y, ((data[i] >> 2) & 1) - ((data[i] >> 1) & 1)); |
@@ -159,11 +158,13 @@ static void cobra_close(struct input_dev *dev) | |||
159 | static int cobra_connect(struct gameport *gameport, struct gameport_driver *drv) | 158 | static int cobra_connect(struct gameport *gameport, struct gameport_driver *drv) |
160 | { | 159 | { |
161 | struct cobra *cobra; | 160 | struct cobra *cobra; |
161 | struct input_dev *input_dev; | ||
162 | unsigned int data[2]; | 162 | unsigned int data[2]; |
163 | int i, j; | 163 | int i, j; |
164 | int err; | 164 | int err; |
165 | 165 | ||
166 | if (!(cobra = kzalloc(sizeof(struct cobra), GFP_KERNEL))) | 166 | cobra = kzalloc(sizeof(struct cobra), GFP_KERNEL); |
167 | if (!cobra) | ||
167 | return -ENOMEM; | 168 | return -ENOMEM; |
168 | 169 | ||
169 | cobra->gameport = gameport; | 170 | cobra->gameport = gameport; |
@@ -191,38 +192,46 @@ static int cobra_connect(struct gameport *gameport, struct gameport_driver *drv) | |||
191 | gameport_set_poll_handler(gameport, cobra_poll); | 192 | gameport_set_poll_handler(gameport, cobra_poll); |
192 | gameport_set_poll_interval(gameport, 20); | 193 | gameport_set_poll_interval(gameport, 20); |
193 | 194 | ||
194 | for (i = 0; i < 2; i++) | 195 | for (i = 0; i < 2; i++) { |
195 | if ((cobra->exists >> i) & 1) { | 196 | if (~(cobra->exists >> i) & 1) |
196 | 197 | continue; | |
197 | sprintf(cobra->phys[i], "%s/input%d", gameport->phys, i); | ||
198 | 198 | ||
199 | cobra->dev[i].private = cobra; | 199 | cobra->dev[i] = input_dev = input_allocate_device(); |
200 | cobra->dev[i].open = cobra_open; | 200 | if (!input_dev) { |
201 | cobra->dev[i].close = cobra_close; | 201 | err = -ENOMEM; |
202 | goto fail3; | ||
203 | } | ||
202 | 204 | ||
203 | cobra->dev[i].name = cobra_name; | 205 | 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 | 206 | ||
210 | cobra->dev[i].evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); | 207 | input_dev->name = "Creative Labs Blaster GamePad Cobra"; |
208 | input_dev->phys = cobra->phys[i]; | ||
209 | input_dev->id.bustype = BUS_GAMEPORT; | ||
210 | input_dev->id.vendor = GAMEPORT_ID_VENDOR_CREATIVE; | ||
211 | input_dev->id.product = 0x0008; | ||
212 | input_dev->id.version = 0x0100; | ||
213 | input_dev->cdev.dev = &gameport->dev; | ||
214 | input_dev->private = cobra; | ||
211 | 215 | ||
212 | input_set_abs_params(&cobra->dev[i], ABS_X, -1, 1, 0, 0); | 216 | input_dev->open = cobra_open; |
213 | input_set_abs_params(&cobra->dev[i], ABS_Y, -1, 1, 0, 0); | 217 | input_dev->close = cobra_close; |
214 | 218 | ||
215 | for (j = 0; cobra_btn[j]; j++) | 219 | input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); |
216 | set_bit(cobra_btn[j], cobra->dev[i].keybit); | 220 | input_set_abs_params(input_dev, ABS_X, -1, 1, 0, 0); |
221 | input_set_abs_params(input_dev, ABS_Y, -1, 1, 0, 0); | ||
222 | for (j = 0; cobra_btn[j]; j++) | ||
223 | set_bit(cobra_btn[j], input_dev->keybit); | ||
217 | 224 | ||
218 | input_register_device(&cobra->dev[i]); | 225 | input_register_device(cobra->dev[i]); |
219 | printk(KERN_INFO "input: %s on %s\n", cobra_name, gameport->phys); | 226 | } |
220 | } | ||
221 | 227 | ||
222 | return 0; | 228 | return 0; |
223 | 229 | ||
224 | fail2: gameport_close(gameport); | 230 | fail3: for (i = 0; i < 2; i++) |
225 | fail1: gameport_set_drvdata(gameport, NULL); | 231 | if (cobra->dev[i]) |
232 | input_unregister_device(cobra->dev[i]); | ||
233 | fail2: gameport_close(gameport); | ||
234 | fail1: gameport_set_drvdata(gameport, NULL); | ||
226 | kfree(cobra); | 235 | kfree(cobra); |
227 | return err; | 236 | return err; |
228 | } | 237 | } |
@@ -234,7 +243,7 @@ static void cobra_disconnect(struct gameport *gameport) | |||
234 | 243 | ||
235 | for (i = 0; i < 2; i++) | 244 | for (i = 0; i < 2; i++) |
236 | if ((cobra->exists >> i) & 1) | 245 | if ((cobra->exists >> i) & 1) |
237 | input_unregister_device(cobra->dev + i); | 246 | input_unregister_device(cobra->dev[i]); |
238 | gameport_close(gameport); | 247 | gameport_close(gameport); |
239 | gameport_set_drvdata(gameport, NULL); | 248 | gameport_set_drvdata(gameport, NULL); |
240 | kfree(cobra); | 249 | 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>"); | |||
43 | MODULE_DESCRIPTION("Atari, Amstrad, Commodore, Amiga, Sega, etc. joystick driver"); | 43 | MODULE_DESCRIPTION("Atari, Amstrad, Commodore, Amiga, Sega, etc. joystick driver"); |
44 | MODULE_LICENSE("GPL"); | 44 | MODULE_LICENSE("GPL"); |
45 | 45 | ||
46 | static int db9[] __initdata = { -1, 0 }; | 46 | struct db9_config { |
47 | static int db9_nargs __initdata = 0; | 47 | int args[2]; |
48 | module_param_array_named(dev, db9, int, &db9_nargs, 0); | 48 | int nargs; |
49 | MODULE_PARM_DESC(dev, "Describes first attached device (<parport#>,<type>)"); | 49 | }; |
50 | 50 | ||
51 | static int db9_2[] __initdata = { -1, 0 }; | 51 | #define DB9_MAX_PORTS 3 |
52 | static int db9_nargs_2 __initdata = 0; | 52 | static struct db9_config db9[DB9_MAX_PORTS] __initdata; |
53 | module_param_array_named(dev2, db9_2, int, &db9_nargs_2, 0); | ||
54 | MODULE_PARM_DESC(dev2, "Describes second attached device (<parport#>,<type>)"); | ||
55 | 53 | ||
56 | static int db9_3[] __initdata = { -1, 0 }; | 54 | module_param_array_named(dev, db9[0].args, int, &db9[0].nargs, 0); |
57 | static int db9_nargs_3 __initdata = 0; | 55 | MODULE_PARM_DESC(dev, "Describes first attached device (<parport#>,<type>)"); |
58 | module_param_array_named(dev3, db9_3, int, &db9_nargs_3, 0); | 56 | module_param_array_named(dev2, db9[1].args, int, &db9[0].nargs, 0); |
57 | MODULE_PARM_DESC(dev2, "Describes second attached device (<parport#>,<type>)"); | ||
58 | module_param_array_named(dev3, db9[2].args, int, &db9[2].nargs, 0); | ||
59 | MODULE_PARM_DESC(dev3, "Describes third attached device (<parport#>,<type>)"); | 59 | MODULE_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 | |||
98 | struct 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 | |||
95 | struct db9 { | 108 | struct 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 | ||
105 | static struct db9 *db9_base[3]; | 118 | static struct db9 *db9_base[3]; |
106 | 119 | ||
107 | static short db9_multi_btn[] = { BTN_TRIGGER, BTN_THUMB }; | 120 | static const short db9_multi_btn[] = { BTN_TRIGGER, BTN_THUMB }; |
108 | static short db9_genesis_btn[] = { BTN_START, BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_MODE }; | 121 | static const short db9_genesis_btn[] = { BTN_START, BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_MODE }; |
109 | static short db9_cd32_btn[] = { BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_TL, BTN_TR, BTN_START }; | 122 | static const short db9_cd32_btn[] = { BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_TL, BTN_TR, BTN_START }; |
110 | |||
111 | static char db9_buttons[DB9_MAX_PAD] = { 0, 1, 2, 4, 0, 6, 8, 9, 1, 1, 7, 9, 9 }; | ||
112 | static 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 }; | ||
115 | static 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 | |||
119 | static const int db9_max_pads[DB9_MAX_PAD] = { 0, 1, 1, 1, 0, 1, 1, 6, 1, 2, 1, 6, 12 }; | ||
120 | static const int db9_num_axis[DB9_MAX_PAD] = { 0, 2, 2, 2, 0, 2, 2, 7, 2, 2, 2 ,7, 7 }; | ||
121 | static const short db9_abs[] = { ABS_X, ABS_Y, ABS_RX, ABS_RY, ABS_RZ, ABS_Z, ABS_HAT0X, ABS_HAT0Y, ABS_HAT1X, ABS_HAT1Y }; | 123 | static const short db9_abs[] = { ABS_X, ABS_Y, ABS_RX, ABS_RY, ABS_RZ, ABS_Z, ABS_HAT0X, ABS_HAT0Y, ABS_HAT1X, ABS_HAT1Y }; |
122 | static const int db9_bidirectional[DB9_MAX_PAD] = { 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0 }; | 124 | |
123 | static const int db9_reverse[DB9_MAX_PAD] = { 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0 }; | 125 | static 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 | ||
542 | static struct db9 __init *db9_probe(int *config, int nargs) | 559 | static 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 | |||
661 | static 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 | ||
631 | static int __init db9_init(void) | 671 | static 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 | ||
643 | static void __exit db9_exit(void) | 706 | static 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 | ||
655 | module_init(db9_init); | 715 | module_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>"); | |||
41 | MODULE_DESCRIPTION("NES, SNES, N64, MultiSystem, PSX gamepad driver"); | 41 | MODULE_DESCRIPTION("NES, SNES, N64, MultiSystem, PSX gamepad driver"); |
42 | MODULE_LICENSE("GPL"); | 42 | MODULE_LICENSE("GPL"); |
43 | 43 | ||
44 | static int gc[] __initdata = { -1, 0, 0, 0, 0, 0 }; | 44 | #define GC_MAX_PORTS 3 |
45 | static int gc_nargs __initdata = 0; | 45 | #define GC_MAX_DEVICES 5 |
46 | module_param_array_named(map, gc, int, &gc_nargs, 0); | ||
47 | MODULE_PARM_DESC(map, "Describers first set of devices (<parport#>,<pad1>,<pad2>,..<pad5>)"); | ||
48 | 46 | ||
49 | static int gc_2[] __initdata = { -1, 0, 0, 0, 0, 0 }; | 47 | struct gc_config { |
50 | static int gc_nargs_2 __initdata = 0; | 48 | int args[GC_MAX_DEVICES + 1]; |
51 | module_param_array_named(map2, gc_2, int, &gc_nargs_2, 0); | 49 | int nargs; |
52 | MODULE_PARM_DESC(map2, "Describers second set of devices"); | 50 | }; |
51 | |||
52 | static struct gc_config gc[GC_MAX_PORTS] __initdata; | ||
53 | 53 | ||
54 | static int gc_3[] __initdata = { -1, 0, 0, 0, 0, 0 }; | 54 | module_param_array_named(map, gc[0].args, int, &gc[0].nargs, 0); |
55 | static int gc_nargs_3 __initdata = 0; | 55 | MODULE_PARM_DESC(map, "Describes first set of devices (<parport#>,<pad1>,<pad2>,..<pad5>)"); |
56 | module_param_array_named(map3, gc_3, int, &gc_nargs_3, 0); | 56 | module_param_array_named(map2, gc[1].args, int, &gc[1].nargs, 0); |
57 | MODULE_PARM_DESC(map3, "Describers third set of devices"); | 57 | MODULE_PARM_DESC(map2, "Describes second set of devices"); |
58 | module_param_array_named(map3, gc[2].args, int, &gc[2].nargs, 0); | ||
59 | MODULE_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 | ||
78 | struct gc { | 80 | struct 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 | ||
88 | static struct gc *gc_base[3]; | 90 | static 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 | |||
330 | static void gc_timer(unsigned long private) | 332 | static 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 | ||
536 | static struct gc __init *gc_probe(int *config, int nargs) | 537 | static 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); | 622 | static 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: | 691 | static 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: | 702 | static 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 | |||
684 | static 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 | ||
696 | static void __exit gc_exit(void) | 736 | static 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 | ||
709 | module_init(gc_init); | 745 | module_init(gc_init); |
diff --git a/drivers/input/joystick/gf2k.c b/drivers/input/joystick/gf2k.c index 8e4f92b115e6..8a3ad455eb38 100644 --- a/drivers/input/joystick/gf2k.c +++ b/drivers/input/joystick/gf2k.c | |||
@@ -35,6 +35,7 @@ | |||
35 | #include <linux/init.h> | 35 | #include <linux/init.h> |
36 | #include <linux/input.h> | 36 | #include <linux/input.h> |
37 | #include <linux/gameport.h> | 37 | #include <linux/gameport.h> |
38 | #include <linux/jiffies.h> | ||
38 | 39 | ||
39 | #define DRIVER_DESC "Genius Flight 2000 joystick driver" | 40 | #define DRIVER_DESC "Genius Flight 2000 joystick driver" |
40 | 41 | ||
@@ -81,7 +82,7 @@ static short gf2k_seq_digital[] = { 590, 320, 860, 0 }; | |||
81 | 82 | ||
82 | struct gf2k { | 83 | struct gf2k { |
83 | struct gameport *gameport; | 84 | struct gameport *gameport; |
84 | struct input_dev dev; | 85 | struct input_dev *dev; |
85 | int reads; | 86 | int reads; |
86 | int bads; | 87 | int bads; |
87 | unsigned char id; | 88 | unsigned char id; |
@@ -175,7 +176,7 @@ static int gf2k_get_bits(unsigned char *buf, int pos, int num, int shift) | |||
175 | 176 | ||
176 | static void gf2k_read(struct gf2k *gf2k, unsigned char *data) | 177 | static void gf2k_read(struct gf2k *gf2k, unsigned char *data) |
177 | { | 178 | { |
178 | struct input_dev *dev = &gf2k->dev; | 179 | struct input_dev *dev = gf2k->dev; |
179 | int i, t; | 180 | int i, t; |
180 | 181 | ||
181 | for (i = 0; i < 4 && i < gf2k_axes[gf2k->id]; i++) | 182 | for (i = 0; i < 4 && i < gf2k_axes[gf2k->id]; i++) |
@@ -239,13 +240,19 @@ static void gf2k_close(struct input_dev *dev) | |||
239 | static int gf2k_connect(struct gameport *gameport, struct gameport_driver *drv) | 240 | static int gf2k_connect(struct gameport *gameport, struct gameport_driver *drv) |
240 | { | 241 | { |
241 | struct gf2k *gf2k; | 242 | struct gf2k *gf2k; |
243 | struct input_dev *input_dev; | ||
242 | unsigned char data[GF2K_LENGTH]; | 244 | unsigned char data[GF2K_LENGTH]; |
243 | int i, err; | 245 | int i, err; |
244 | 246 | ||
245 | if (!(gf2k = kzalloc(sizeof(struct gf2k), GFP_KERNEL))) | 247 | gf2k = kzalloc(sizeof(struct gf2k), GFP_KERNEL); |
246 | return -ENOMEM; | 248 | input_dev = input_allocate_device(); |
249 | if (!gf2k || !input_dev) { | ||
250 | err = -ENOMEM; | ||
251 | goto fail1; | ||
252 | } | ||
247 | 253 | ||
248 | gf2k->gameport = gameport; | 254 | gf2k->gameport = gameport; |
255 | gf2k->dev = input_dev; | ||
249 | 256 | ||
250 | gameport_set_drvdata(gameport, gf2k); | 257 | gameport_set_drvdata(gameport, gf2k); |
251 | 258 | ||
@@ -295,53 +302,52 @@ static int gf2k_connect(struct gameport *gameport, struct gameport_driver *drv) | |||
295 | 302 | ||
296 | gf2k->length = gf2k_lens[gf2k->id]; | 303 | gf2k->length = gf2k_lens[gf2k->id]; |
297 | 304 | ||
298 | init_input_dev(&gf2k->dev); | 305 | input_dev->name = gf2k_names[gf2k->id]; |
299 | 306 | input_dev->phys = gf2k->phys; | |
300 | gf2k->dev.private = gf2k; | 307 | input_dev->id.bustype = BUS_GAMEPORT; |
301 | gf2k->dev.open = gf2k_open; | 308 | input_dev->id.vendor = GAMEPORT_ID_VENDOR_GENIUS; |
302 | gf2k->dev.close = gf2k_close; | 309 | input_dev->id.product = gf2k->id; |
303 | gf2k->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); | 310 | input_dev->id.version = 0x0100; |
311 | input_dev->cdev.dev = &gameport->dev; | ||
312 | input_dev->private = gf2k; | ||
304 | 313 | ||
305 | gf2k->dev.name = gf2k_names[gf2k->id]; | 314 | input_dev->open = gf2k_open; |
306 | gf2k->dev.phys = gf2k->phys; | 315 | input_dev->close = gf2k_close; |
307 | gf2k->dev.id.bustype = BUS_GAMEPORT; | 316 | 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 | 317 | ||
312 | for (i = 0; i < gf2k_axes[gf2k->id]; i++) | 318 | for (i = 0; i < gf2k_axes[gf2k->id]; i++) |
313 | set_bit(gf2k_abs[i], gf2k->dev.absbit); | 319 | set_bit(gf2k_abs[i], input_dev->absbit); |
314 | 320 | ||
315 | for (i = 0; i < gf2k_hats[gf2k->id]; i++) { | 321 | for (i = 0; i < gf2k_hats[gf2k->id]; i++) { |
316 | set_bit(ABS_HAT0X + i, gf2k->dev.absbit); | 322 | set_bit(ABS_HAT0X + i, input_dev->absbit); |
317 | gf2k->dev.absmin[ABS_HAT0X + i] = -1; | 323 | input_dev->absmin[ABS_HAT0X + i] = -1; |
318 | gf2k->dev.absmax[ABS_HAT0X + i] = 1; | 324 | input_dev->absmax[ABS_HAT0X + i] = 1; |
319 | } | 325 | } |
320 | 326 | ||
321 | for (i = 0; i < gf2k_joys[gf2k->id]; i++) | 327 | for (i = 0; i < gf2k_joys[gf2k->id]; i++) |
322 | set_bit(gf2k_btn_joy[i], gf2k->dev.keybit); | 328 | set_bit(gf2k_btn_joy[i], input_dev->keybit); |
323 | 329 | ||
324 | for (i = 0; i < gf2k_pads[gf2k->id]; i++) | 330 | for (i = 0; i < gf2k_pads[gf2k->id]; i++) |
325 | set_bit(gf2k_btn_pad[i], gf2k->dev.keybit); | 331 | set_bit(gf2k_btn_pad[i], input_dev->keybit); |
326 | 332 | ||
327 | gf2k_read_packet(gameport, gf2k->length, data); | 333 | gf2k_read_packet(gameport, gf2k->length, data); |
328 | gf2k_read(gf2k, data); | 334 | gf2k_read(gf2k, data); |
329 | 335 | ||
330 | for (i = 0; i < gf2k_axes[gf2k->id]; i++) { | 336 | 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 : | 337 | 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; | 338 | input_dev->abs[gf2k_abs[0]] + input_dev->abs[gf2k_abs[1]] - 32; |
333 | gf2k->dev.absmin[gf2k_abs[i]] = 32; | 339 | input_dev->absmin[gf2k_abs[i]] = 32; |
334 | gf2k->dev.absfuzz[gf2k_abs[i]] = 8; | 340 | input_dev->absfuzz[gf2k_abs[i]] = 8; |
335 | gf2k->dev.absflat[gf2k_abs[i]] = (i < 2) ? 24 : 0; | 341 | input_dev->absflat[gf2k_abs[i]] = (i < 2) ? 24 : 0; |
336 | } | 342 | } |
337 | 343 | ||
338 | input_register_device(&gf2k->dev); | 344 | input_register_device(gf2k->dev); |
339 | printk(KERN_INFO "input: %s on %s\n", gf2k_names[gf2k->id], gameport->phys); | ||
340 | 345 | ||
341 | return 0; | 346 | return 0; |
342 | 347 | ||
343 | fail2: gameport_close(gameport); | 348 | fail2: gameport_close(gameport); |
344 | fail1: gameport_set_drvdata(gameport, NULL); | 349 | fail1: gameport_set_drvdata(gameport, NULL); |
350 | input_free_device(input_dev); | ||
345 | kfree(gf2k); | 351 | kfree(gf2k); |
346 | return err; | 352 | return err; |
347 | } | 353 | } |
@@ -350,7 +356,7 @@ static void gf2k_disconnect(struct gameport *gameport) | |||
350 | { | 356 | { |
351 | struct gf2k *gf2k = gameport_get_drvdata(gameport); | 357 | struct gf2k *gf2k = gameport_get_drvdata(gameport); |
352 | 358 | ||
353 | input_unregister_device(&gf2k->dev); | 359 | input_unregister_device(gf2k->dev); |
354 | gameport_close(gameport); | 360 | gameport_close(gameport); |
355 | gameport_set_drvdata(gameport, NULL); | 361 | gameport_set_drvdata(gameport, NULL); |
356 | kfree(gf2k); | 362 | kfree(gf2k); |
diff --git a/drivers/input/joystick/grip.c b/drivers/input/joystick/grip.c index 9d3f910dd568..a936e7aedb10 100644 --- a/drivers/input/joystick/grip.c +++ b/drivers/input/joystick/grip.c | |||
@@ -34,6 +34,7 @@ | |||
34 | #include <linux/slab.h> | 34 | #include <linux/slab.h> |
35 | #include <linux/gameport.h> | 35 | #include <linux/gameport.h> |
36 | #include <linux/input.h> | 36 | #include <linux/input.h> |
37 | #include <linux/jiffies.h> | ||
37 | 38 | ||
38 | #define DRIVER_DESC "Gravis GrIP protocol joystick driver" | 39 | #define DRIVER_DESC "Gravis GrIP protocol joystick driver" |
39 | 40 | ||
@@ -55,7 +56,7 @@ MODULE_LICENSE("GPL"); | |||
55 | 56 | ||
56 | struct grip { | 57 | struct grip { |
57 | struct gameport *gameport; | 58 | struct gameport *gameport; |
58 | struct input_dev dev[2]; | 59 | struct input_dev *dev[2]; |
59 | unsigned char mode[2]; | 60 | unsigned char mode[2]; |
60 | int reads; | 61 | int reads; |
61 | int bads; | 62 | int bads; |
@@ -190,7 +191,7 @@ static void grip_poll(struct gameport *gameport) | |||
190 | 191 | ||
191 | for (i = 0; i < 2; i++) { | 192 | for (i = 0; i < 2; i++) { |
192 | 193 | ||
193 | dev = grip->dev + i; | 194 | dev = grip->dev[i]; |
194 | grip->reads++; | 195 | grip->reads++; |
195 | 196 | ||
196 | switch (grip->mode[i]) { | 197 | switch (grip->mode[i]) { |
@@ -297,6 +298,7 @@ static void grip_close(struct input_dev *dev) | |||
297 | static int grip_connect(struct gameport *gameport, struct gameport_driver *drv) | 298 | static int grip_connect(struct gameport *gameport, struct gameport_driver *drv) |
298 | { | 299 | { |
299 | struct grip *grip; | 300 | struct grip *grip; |
301 | struct input_dev *input_dev; | ||
300 | unsigned int data[GRIP_LENGTH_XT]; | 302 | unsigned int data[GRIP_LENGTH_XT]; |
301 | int i, j, t; | 303 | int i, j, t; |
302 | int err; | 304 | int err; |
@@ -339,48 +341,56 @@ static int grip_connect(struct gameport *gameport, struct gameport_driver *drv) | |||
339 | gameport_set_poll_handler(gameport, grip_poll); | 341 | gameport_set_poll_handler(gameport, grip_poll); |
340 | gameport_set_poll_interval(gameport, 20); | 342 | gameport_set_poll_interval(gameport, 20); |
341 | 343 | ||
342 | for (i = 0; i < 2; i++) | 344 | for (i = 0; i < 2; i++) { |
343 | if (grip->mode[i]) { | 345 | if (!grip->mode[i]) |
346 | continue; | ||
344 | 347 | ||
345 | sprintf(grip->phys[i], "%s/input%d", gameport->phys, i); | 348 | grip->dev[i] = input_dev = input_allocate_device(); |
349 | if (!input_dev) { | ||
350 | err = -ENOMEM; | ||
351 | goto fail3; | ||
352 | } | ||
346 | 353 | ||
347 | grip->dev[i].private = grip; | 354 | sprintf(grip->phys[i], "%s/input%d", gameport->phys, i); |
348 | 355 | ||
349 | grip->dev[i].open = grip_open; | 356 | input_dev->name = grip_name[grip->mode[i]]; |
350 | grip->dev[i].close = grip_close; | 357 | input_dev->phys = grip->phys[i]; |
358 | input_dev->id.bustype = BUS_GAMEPORT; | ||
359 | input_dev->id.vendor = GAMEPORT_ID_VENDOR_GRAVIS; | ||
360 | input_dev->id.product = grip->mode[i]; | ||
361 | input_dev->id.version = 0x0100; | ||
362 | input_dev->cdev.dev = &gameport->dev; | ||
363 | input_dev->private = grip; | ||
351 | 364 | ||
352 | grip->dev[i].name = grip_name[grip->mode[i]]; | 365 | input_dev->open = grip_open; |
353 | grip->dev[i].phys = grip->phys[i]; | 366 | 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 | 367 | ||
359 | grip->dev[i].evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); | 368 | input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); |
360 | 369 | ||
361 | for (j = 0; (t = grip_abs[grip->mode[i]][j]) >= 0; j++) { | 370 | for (j = 0; (t = grip_abs[grip->mode[i]][j]) >= 0; j++) { |
362 | 371 | ||
363 | if (j < grip_cen[grip->mode[i]]) | 372 | if (j < grip_cen[grip->mode[i]]) |
364 | input_set_abs_params(&grip->dev[i], t, 14, 52, 1, 2); | 373 | input_set_abs_params(input_dev, t, 14, 52, 1, 2); |
365 | else if (j < grip_anx[grip->mode[i]]) | 374 | else if (j < grip_anx[grip->mode[i]]) |
366 | input_set_abs_params(&grip->dev[i], t, 3, 57, 1, 0); | 375 | input_set_abs_params(input_dev, t, 3, 57, 1, 0); |
367 | else | 376 | else |
368 | input_set_abs_params(&grip->dev[i], t, -1, 1, 0, 0); | 377 | input_set_abs_params(input_dev, t, -1, 1, 0, 0); |
369 | } | 378 | } |
370 | 379 | ||
371 | for (j = 0; (t = grip_btn[grip->mode[i]][j]) >= 0; j++) | 380 | for (j = 0; (t = grip_btn[grip->mode[i]][j]) >= 0; j++) |
372 | if (t > 0) | 381 | if (t > 0) |
373 | set_bit(t, grip->dev[i].keybit); | 382 | set_bit(t, input_dev->keybit); |
374 | 383 | ||
375 | printk(KERN_INFO "input: %s on %s\n", | 384 | input_register_device(grip->dev[i]); |
376 | grip_name[grip->mode[i]], gameport->phys); | 385 | } |
377 | input_register_device(grip->dev + i); | ||
378 | } | ||
379 | 386 | ||
380 | return 0; | 387 | return 0; |
381 | 388 | ||
382 | fail2: gameport_close(gameport); | 389 | fail3: for (i = 0; i < 2; i++) |
383 | fail1: gameport_set_drvdata(gameport, NULL); | 390 | if (grip->dev[i]) |
391 | input_unregister_device(grip->dev[i]); | ||
392 | fail2: gameport_close(gameport); | ||
393 | fail1: gameport_set_drvdata(gameport, NULL); | ||
384 | kfree(grip); | 394 | kfree(grip); |
385 | return err; | 395 | return err; |
386 | } | 396 | } |
@@ -391,8 +401,8 @@ static void grip_disconnect(struct gameport *gameport) | |||
391 | int i; | 401 | int i; |
392 | 402 | ||
393 | for (i = 0; i < 2; i++) | 403 | for (i = 0; i < 2; i++) |
394 | if (grip->mode[i]) | 404 | if (grip->dev[i]) |
395 | input_unregister_device(grip->dev + i); | 405 | input_unregister_device(grip->dev[i]); |
396 | gameport_close(gameport); | 406 | gameport_close(gameport); |
397 | gameport_set_drvdata(gameport, NULL); | 407 | gameport_set_drvdata(gameport, NULL); |
398 | kfree(grip); | 408 | kfree(grip); |
diff --git a/drivers/input/joystick/grip_mp.c b/drivers/input/joystick/grip_mp.c index da17eee6f574..51a912222e85 100644 --- a/drivers/input/joystick/grip_mp.c +++ b/drivers/input/joystick/grip_mp.c | |||
@@ -19,6 +19,7 @@ | |||
19 | #include <linux/input.h> | 19 | #include <linux/input.h> |
20 | #include <linux/delay.h> | 20 | #include <linux/delay.h> |
21 | #include <linux/proc_fs.h> | 21 | #include <linux/proc_fs.h> |
22 | #include <linux/jiffies.h> | ||
22 | 23 | ||
23 | #define DRIVER_DESC "Gravis Grip Multiport driver" | 24 | #define DRIVER_DESC "Gravis Grip Multiport driver" |
24 | 25 | ||
@@ -32,23 +33,37 @@ MODULE_LICENSE("GPL"); | |||
32 | #define dbg(format, arg...) do {} while (0) | 33 | #define dbg(format, arg...) do {} while (0) |
33 | #endif | 34 | #endif |
34 | 35 | ||
36 | #define GRIP_MAX_PORTS 4 | ||
35 | /* | 37 | /* |
36 | * Grip multiport state | 38 | * Grip multiport state |
37 | */ | 39 | */ |
38 | 40 | ||
41 | struct grip_port { | ||
42 | struct input_dev *dev; | ||
43 | int mode; | ||
44 | int registered; | ||
45 | |||
46 | /* individual gamepad states */ | ||
47 | int buttons; | ||
48 | int xaxes; | ||
49 | int yaxes; | ||
50 | int dirty; /* has the state been updated? */ | ||
51 | }; | ||
52 | |||
39 | struct grip_mp { | 53 | struct grip_mp { |
40 | struct gameport *gameport; | 54 | struct gameport *gameport; |
41 | struct input_dev dev[4]; | 55 | struct grip_port *port[GRIP_MAX_PORTS]; |
42 | int mode[4]; | 56 | // struct input_dev *dev[4]; |
43 | int registered[4]; | 57 | // int mode[4]; |
58 | // int registered[4]; | ||
44 | int reads; | 59 | int reads; |
45 | int bads; | 60 | int bads; |
46 | 61 | ||
47 | /* individual gamepad states */ | 62 | /* individual gamepad states */ |
48 | int buttons[4]; | 63 | // int buttons[4]; |
49 | int xaxes[4]; | 64 | // int xaxes[4]; |
50 | int yaxes[4]; | 65 | // int yaxes[4]; |
51 | int dirty[4]; /* has the state been updated? */ | 66 | // int dirty[4]; /* has the state been updated? */ |
52 | }; | 67 | }; |
53 | 68 | ||
54 | /* | 69 | /* |
@@ -85,16 +100,16 @@ struct grip_mp { | |||
85 | #define GRIP_MODE_GP 2 | 100 | #define GRIP_MODE_GP 2 |
86 | #define GRIP_MODE_C64 3 | 101 | #define GRIP_MODE_C64 3 |
87 | 102 | ||
88 | static int grip_btn_gp[] = { BTN_TR, BTN_TL, BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, -1 }; | 103 | static const int grip_btn_gp[] = { BTN_TR, BTN_TL, BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, -1 }; |
89 | static int grip_btn_c64[] = { BTN_JOYSTICK, -1 }; | 104 | static const int grip_btn_c64[] = { BTN_JOYSTICK, -1 }; |
90 | 105 | ||
91 | static int grip_abs_gp[] = { ABS_X, ABS_Y, -1 }; | 106 | static const int grip_abs_gp[] = { ABS_X, ABS_Y, -1 }; |
92 | static int grip_abs_c64[] = { ABS_X, ABS_Y, -1 }; | 107 | static const int grip_abs_c64[] = { ABS_X, ABS_Y, -1 }; |
93 | 108 | ||
94 | static int *grip_abs[] = { NULL, NULL, grip_abs_gp, grip_abs_c64 }; | 109 | static const int *grip_abs[] = { NULL, NULL, grip_abs_gp, grip_abs_c64 }; |
95 | static int *grip_btn[] = { NULL, NULL, grip_btn_gp, grip_btn_c64 }; | 110 | static const int *grip_btn[] = { NULL, NULL, grip_btn_gp, grip_btn_c64 }; |
96 | 111 | ||
97 | static char *grip_name[] = { NULL, NULL, "Gravis Grip Pad", "Commodore 64 Joystick" }; | 112 | static const char *grip_name[] = { NULL, NULL, "Gravis Grip Pad", "Commodore 64 Joystick" }; |
98 | 113 | ||
99 | static const int init_seq[] = { | 114 | static 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, | 115 | 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 +119,9 @@ static const int init_seq[] = { | |||
104 | 119 | ||
105 | /* Maps multiport directional values to X,Y axis values (each axis encoded in 3 bits) */ | 120 | /* Maps multiport directional values to X,Y axis values (each axis encoded in 3 bits) */ |
106 | 121 | ||
107 | static int axis_map[] = { 5, 9, 1, 5, 6, 10, 2, 6, 4, 8, 0, 4, 5, 9, 1, 5 }; | 122 | static const int axis_map[] = { 5, 9, 1, 5, 6, 10, 2, 6, 4, 8, 0, 4, 5, 9, 1, 5 }; |
108 | 123 | ||
109 | static void register_slot(int i, struct grip_mp *grip); | 124 | static int register_slot(int i, struct grip_mp *grip); |
110 | 125 | ||
111 | /* | 126 | /* |
112 | * Returns whether an odd or even number of bits are on in pkt. | 127 | * Returns whether an odd or even number of bits are on in pkt. |
@@ -353,9 +368,10 @@ static int dig_mode_start(struct gameport *gameport, u32 *packet) | |||
353 | 368 | ||
354 | static int get_and_decode_packet(struct grip_mp *grip, int flags) | 369 | static int get_and_decode_packet(struct grip_mp *grip, int flags) |
355 | { | 370 | { |
371 | struct grip_port *port; | ||
356 | u32 packet; | 372 | u32 packet; |
357 | int joytype = 0; | 373 | int joytype = 0; |
358 | int slot = 0; | 374 | int slot; |
359 | 375 | ||
360 | /* Get a packet and check for validity */ | 376 | /* Get a packet and check for validity */ |
361 | 377 | ||
@@ -377,6 +393,8 @@ static int get_and_decode_packet(struct grip_mp *grip, int flags) | |||
377 | if ((slot < 0) || (slot > 3)) | 393 | if ((slot < 0) || (slot > 3)) |
378 | return flags; | 394 | return flags; |
379 | 395 | ||
396 | port = grip->port[slot]; | ||
397 | |||
380 | /* | 398 | /* |
381 | * Handle "reset" packets, which occur at startup, and when gamepads | 399 | * Handle "reset" packets, which occur at startup, and when gamepads |
382 | * are removed or plugged in. May contain configuration of a new gamepad. | 400 | * are removed or plugged in. May contain configuration of a new gamepad. |
@@ -385,14 +403,14 @@ static int get_and_decode_packet(struct grip_mp *grip, int flags) | |||
385 | joytype = (packet >> 16) & 0x1f; | 403 | joytype = (packet >> 16) & 0x1f; |
386 | if (!joytype) { | 404 | if (!joytype) { |
387 | 405 | ||
388 | if (grip->registered[slot]) { | 406 | if (port->registered) { |
389 | printk(KERN_INFO "grip_mp: removing %s, slot %d\n", | 407 | printk(KERN_INFO "grip_mp: removing %s, slot %d\n", |
390 | grip_name[grip->mode[slot]], slot); | 408 | grip_name[port->mode], slot); |
391 | input_unregister_device(grip->dev + slot); | 409 | input_unregister_device(port->dev); |
392 | grip->registered[slot] = 0; | 410 | port->registered = 0; |
393 | } | 411 | } |
394 | dbg("Reset: grip multiport slot %d\n", slot); | 412 | dbg("Reset: grip multiport slot %d\n", slot); |
395 | grip->mode[slot] = GRIP_MODE_RESET; | 413 | port->mode = GRIP_MODE_RESET; |
396 | flags |= IO_SLOT_CHANGE; | 414 | flags |= IO_SLOT_CHANGE; |
397 | return flags; | 415 | return flags; |
398 | } | 416 | } |
@@ -402,17 +420,17 @@ static int get_and_decode_packet(struct grip_mp *grip, int flags) | |||
402 | if (joytype == 0x1f) { | 420 | if (joytype == 0x1f) { |
403 | 421 | ||
404 | int dir = (packet >> 8) & 0xf; /* eight way directional value */ | 422 | int dir = (packet >> 8) & 0xf; /* eight way directional value */ |
405 | grip->buttons[slot] = (~packet) & 0xff; | 423 | port->buttons = (~packet) & 0xff; |
406 | grip->yaxes[slot] = ((axis_map[dir] >> 2) & 3) - 1; | 424 | port->yaxes = ((axis_map[dir] >> 2) & 3) - 1; |
407 | grip->xaxes[slot] = (axis_map[dir] & 3) - 1; | 425 | port->xaxes = (axis_map[dir] & 3) - 1; |
408 | grip->dirty[slot] = 1; | 426 | port->dirty = 1; |
409 | 427 | ||
410 | if (grip->mode[slot] == GRIP_MODE_RESET) | 428 | if (port->mode == GRIP_MODE_RESET) |
411 | flags |= IO_SLOT_CHANGE; | 429 | flags |= IO_SLOT_CHANGE; |
412 | 430 | ||
413 | grip->mode[slot] = GRIP_MODE_GP; | 431 | port->mode = GRIP_MODE_GP; |
414 | 432 | ||
415 | if (!grip->registered[slot]) { | 433 | if (!port->registered) { |
416 | dbg("New Grip pad in multiport slot %d.\n", slot); | 434 | dbg("New Grip pad in multiport slot %d.\n", slot); |
417 | register_slot(slot, grip); | 435 | register_slot(slot, grip); |
418 | } | 436 | } |
@@ -445,9 +463,9 @@ static int slots_valid(struct grip_mp *grip) | |||
445 | return 0; | 463 | return 0; |
446 | 464 | ||
447 | for (slot = 0; slot < 4; slot++) { | 465 | for (slot = 0; slot < 4; slot++) { |
448 | if (grip->mode[slot] == GRIP_MODE_RESET) | 466 | if (grip->port[slot]->mode == GRIP_MODE_RESET) |
449 | invalid = 1; | 467 | invalid = 1; |
450 | if (grip->mode[slot] != GRIP_MODE_NONE) | 468 | if (grip->port[slot]->mode != GRIP_MODE_NONE) |
451 | active = 1; | 469 | active = 1; |
452 | } | 470 | } |
453 | 471 | ||
@@ -484,7 +502,7 @@ static int multiport_init(struct grip_mp *grip) | |||
484 | 502 | ||
485 | /* Get packets, store multiport state, and check state's validity */ | 503 | /* Get packets, store multiport state, and check state's validity */ |
486 | for (tries = 0; tries < 4096; tries++) { | 504 | for (tries = 0; tries < 4096; tries++) { |
487 | if ( slots_valid(grip) ) { | 505 | if (slots_valid(grip)) { |
488 | initialized = 1; | 506 | initialized = 1; |
489 | break; | 507 | break; |
490 | } | 508 | } |
@@ -499,24 +517,24 @@ static int multiport_init(struct grip_mp *grip) | |||
499 | 517 | ||
500 | static void report_slot(struct grip_mp *grip, int slot) | 518 | static void report_slot(struct grip_mp *grip, int slot) |
501 | { | 519 | { |
502 | struct input_dev *dev = &(grip->dev[slot]); | 520 | struct grip_port *port = grip->port[slot]; |
503 | int i, buttons = grip->buttons[slot]; | 521 | int i; |
504 | 522 | ||
505 | /* Store button states with linux input driver */ | 523 | /* Store button states with linux input driver */ |
506 | 524 | ||
507 | for (i = 0; i < 8; i++) | 525 | for (i = 0; i < 8; i++) |
508 | input_report_key(dev, grip_btn_gp[i], (buttons >> i) & 1); | 526 | input_report_key(port->dev, grip_btn_gp[i], (port->buttons >> i) & 1); |
509 | 527 | ||
510 | /* Store axis states with linux driver */ | 528 | /* Store axis states with linux driver */ |
511 | 529 | ||
512 | input_report_abs(dev, ABS_X, grip->xaxes[slot]); | 530 | input_report_abs(port->dev, ABS_X, port->xaxes); |
513 | input_report_abs(dev, ABS_Y, grip->yaxes[slot]); | 531 | input_report_abs(port->dev, ABS_Y, port->yaxes); |
514 | 532 | ||
515 | /* Tell the receiver of the events to process them */ | 533 | /* Tell the receiver of the events to process them */ |
516 | 534 | ||
517 | input_sync(dev); | 535 | input_sync(port->dev); |
518 | 536 | ||
519 | grip->dirty[slot] = 0; | 537 | port->dirty = 0; |
520 | } | 538 | } |
521 | 539 | ||
522 | /* | 540 | /* |
@@ -540,7 +558,7 @@ static void grip_poll(struct gameport *gameport) | |||
540 | } | 558 | } |
541 | 559 | ||
542 | for (i = 0; i < 4; i++) | 560 | for (i = 0; i < 4; i++) |
543 | if (grip->dirty[i]) | 561 | if (grip->port[i]->dirty) |
544 | report_slot(grip, i); | 562 | report_slot(grip, i); |
545 | } | 563 | } |
546 | 564 | ||
@@ -571,35 +589,43 @@ static void grip_close(struct input_dev *dev) | |||
571 | * Tell the linux input layer about a newly plugged-in gamepad. | 589 | * Tell the linux input layer about a newly plugged-in gamepad. |
572 | */ | 590 | */ |
573 | 591 | ||
574 | static void register_slot(int slot, struct grip_mp *grip) | 592 | static int register_slot(int slot, struct grip_mp *grip) |
575 | { | 593 | { |
594 | struct grip_port *port = grip->port[slot]; | ||
595 | struct input_dev *input_dev; | ||
576 | int j, t; | 596 | int j, t; |
577 | 597 | ||
578 | grip->dev[slot].private = grip; | 598 | port->dev = input_dev = input_allocate_device(); |
579 | grip->dev[slot].open = grip_open; | 599 | if (!input_dev) |
580 | grip->dev[slot].close = grip_close; | 600 | return -ENOMEM; |
581 | grip->dev[slot].name = grip_name[grip->mode[slot]]; | 601 | |
582 | grip->dev[slot].id.bustype = BUS_GAMEPORT; | 602 | input_dev->name = grip_name[port->mode]; |
583 | grip->dev[slot].id.vendor = GAMEPORT_ID_VENDOR_GRAVIS; | 603 | input_dev->id.bustype = BUS_GAMEPORT; |
584 | grip->dev[slot].id.product = 0x0100 + grip->mode[slot]; | 604 | input_dev->id.vendor = GAMEPORT_ID_VENDOR_GRAVIS; |
585 | grip->dev[slot].id.version = 0x0100; | 605 | input_dev->id.product = 0x0100 + port->mode; |
586 | grip->dev[slot].evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); | 606 | input_dev->id.version = 0x0100; |
607 | input_dev->cdev.dev = &grip->gameport->dev; | ||
608 | input_dev->private = grip; | ||
609 | |||
610 | input_dev->open = grip_open; | ||
611 | input_dev->close = grip_close; | ||
587 | 612 | ||
588 | for (j = 0; (t = grip_abs[grip->mode[slot]][j]) >= 0; j++) | 613 | input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); |
589 | input_set_abs_params(&grip->dev[slot], t, -1, 1, 0, 0); | ||
590 | 614 | ||
591 | for (j = 0; (t = grip_btn[grip->mode[slot]][j]) >= 0; j++) | 615 | for (j = 0; (t = grip_abs[port->mode][j]) >= 0; j++) |
616 | input_set_abs_params(input_dev, t, -1, 1, 0, 0); | ||
617 | |||
618 | for (j = 0; (t = grip_btn[port->mode][j]) >= 0; j++) | ||
592 | if (t > 0) | 619 | if (t > 0) |
593 | set_bit(t, grip->dev[slot].keybit); | 620 | set_bit(t, input_dev->keybit); |
594 | 621 | ||
595 | input_register_device(grip->dev + slot); | 622 | input_register_device(port->dev); |
596 | grip->registered[slot] = 1; | 623 | port->registered = 1; |
597 | 624 | ||
598 | if (grip->dirty[slot]) /* report initial state, if any */ | 625 | if (port->dirty) /* report initial state, if any */ |
599 | report_slot(grip, slot); | 626 | report_slot(grip, slot); |
600 | 627 | ||
601 | printk(KERN_INFO "grip_mp: added %s, slot %d\n", | 628 | return 0; |
602 | grip_name[grip->mode[slot]], slot); | ||
603 | } | 629 | } |
604 | 630 | ||
605 | static int grip_connect(struct gameport *gameport, struct gameport_driver *drv) | 631 | static int grip_connect(struct gameport *gameport, struct gameport_driver *drv) |
@@ -626,7 +652,7 @@ static int grip_connect(struct gameport *gameport, struct gameport_driver *drv) | |||
626 | goto fail2; | 652 | goto fail2; |
627 | } | 653 | } |
628 | 654 | ||
629 | if (!grip->mode[0] && !grip->mode[1] && !grip->mode[2] && !grip->mode[3]) { | 655 | if (!grip->port[0]->mode && !grip->port[1]->mode && !grip->port[2]->mode && !grip->port[3]->mode) { |
630 | /* nothing plugged in */ | 656 | /* nothing plugged in */ |
631 | err = -ENODEV; | 657 | err = -ENODEV; |
632 | goto fail2; | 658 | goto fail2; |
@@ -646,8 +672,8 @@ static void grip_disconnect(struct gameport *gameport) | |||
646 | int i; | 672 | int i; |
647 | 673 | ||
648 | for (i = 0; i < 4; i++) | 674 | for (i = 0; i < 4; i++) |
649 | if (grip->registered[i]) | 675 | if (grip->port[i]->registered) |
650 | input_unregister_device(grip->dev + i); | 676 | input_unregister_device(grip->port[i]->dev); |
651 | gameport_close(gameport); | 677 | gameport_close(gameport); |
652 | gameport_set_drvdata(gameport, NULL); | 678 | gameport_set_drvdata(gameport, NULL); |
653 | kfree(grip); | 679 | kfree(grip); |
diff --git a/drivers/input/joystick/guillemot.c b/drivers/input/joystick/guillemot.c index 6a70ec429f06..6e2c721c26ba 100644 --- a/drivers/input/joystick/guillemot.c +++ b/drivers/input/joystick/guillemot.c | |||
@@ -35,6 +35,7 @@ | |||
35 | #include <linux/init.h> | 35 | #include <linux/init.h> |
36 | #include <linux/gameport.h> | 36 | #include <linux/gameport.h> |
37 | #include <linux/input.h> | 37 | #include <linux/input.h> |
38 | #include <linux/jiffies.h> | ||
38 | 39 | ||
39 | #define DRIVER_DESC "Guillemot Digital joystick driver" | 40 | #define DRIVER_DESC "Guillemot Digital joystick driver" |
40 | 41 | ||
@@ -67,7 +68,7 @@ struct guillemot_type { | |||
67 | 68 | ||
68 | struct guillemot { | 69 | struct guillemot { |
69 | struct gameport *gameport; | 70 | struct gameport *gameport; |
70 | struct input_dev dev; | 71 | struct input_dev *dev; |
71 | int bads; | 72 | int bads; |
72 | int reads; | 73 | int reads; |
73 | struct guillemot_type *type; | 74 | struct guillemot_type *type; |
@@ -123,7 +124,7 @@ static int guillemot_read_packet(struct gameport *gameport, u8 *data) | |||
123 | static void guillemot_poll(struct gameport *gameport) | 124 | static void guillemot_poll(struct gameport *gameport) |
124 | { | 125 | { |
125 | struct guillemot *guillemot = gameport_get_drvdata(gameport); | 126 | struct guillemot *guillemot = gameport_get_drvdata(gameport); |
126 | struct input_dev *dev = &guillemot->dev; | 127 | struct input_dev *dev = guillemot->dev; |
127 | u8 data[GUILLEMOT_MAX_LENGTH]; | 128 | u8 data[GUILLEMOT_MAX_LENGTH]; |
128 | int i; | 129 | int i; |
129 | 130 | ||
@@ -179,14 +180,20 @@ static void guillemot_close(struct input_dev *dev) | |||
179 | static int guillemot_connect(struct gameport *gameport, struct gameport_driver *drv) | 180 | static int guillemot_connect(struct gameport *gameport, struct gameport_driver *drv) |
180 | { | 181 | { |
181 | struct guillemot *guillemot; | 182 | struct guillemot *guillemot; |
183 | struct input_dev *input_dev; | ||
182 | u8 data[GUILLEMOT_MAX_LENGTH]; | 184 | u8 data[GUILLEMOT_MAX_LENGTH]; |
183 | int i, t; | 185 | int i, t; |
184 | int err; | 186 | int err; |
185 | 187 | ||
186 | if (!(guillemot = kzalloc(sizeof(struct guillemot), GFP_KERNEL))) | 188 | guillemot = kzalloc(sizeof(struct guillemot), GFP_KERNEL); |
187 | return -ENOMEM; | 189 | input_dev = input_allocate_device(); |
190 | if (!guillemot || !input_dev) { | ||
191 | err = -ENOMEM; | ||
192 | goto fail1; | ||
193 | } | ||
188 | 194 | ||
189 | guillemot->gameport = gameport; | 195 | guillemot->gameport = gameport; |
196 | guillemot->dev = input_dev; | ||
190 | 197 | ||
191 | gameport_set_drvdata(gameport, guillemot); | 198 | gameport_set_drvdata(gameport, guillemot); |
192 | 199 | ||
@@ -216,41 +223,40 @@ static int guillemot_connect(struct gameport *gameport, struct gameport_driver * | |||
216 | gameport_set_poll_interval(gameport, 20); | 223 | gameport_set_poll_interval(gameport, 20); |
217 | 224 | ||
218 | sprintf(guillemot->phys, "%s/input0", gameport->phys); | 225 | sprintf(guillemot->phys, "%s/input0", gameport->phys); |
219 | |||
220 | guillemot->type = guillemot_type + i; | 226 | guillemot->type = guillemot_type + i; |
221 | 227 | ||
222 | guillemot->dev.private = guillemot; | 228 | input_dev->name = guillemot_type[i].name; |
223 | guillemot->dev.open = guillemot_open; | 229 | input_dev->phys = guillemot->phys; |
224 | guillemot->dev.close = guillemot_close; | 230 | input_dev->id.bustype = BUS_GAMEPORT; |
231 | input_dev->id.vendor = GAMEPORT_ID_VENDOR_GUILLEMOT; | ||
232 | input_dev->id.product = guillemot_type[i].id; | ||
233 | input_dev->id.version = (int)data[14] << 8 | data[15]; | ||
234 | input_dev->cdev.dev = &gameport->dev; | ||
235 | input_dev->private = guillemot; | ||
225 | 236 | ||
226 | guillemot->dev.name = guillemot_type[i].name; | 237 | input_dev->open = guillemot_open; |
227 | guillemot->dev.phys = guillemot->phys; | 238 | 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 | 239 | ||
233 | guillemot->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); | 240 | input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); |
234 | 241 | ||
235 | for (i = 0; (t = guillemot->type->abs[i]) >= 0; i++) | 242 | for (i = 0; (t = guillemot->type->abs[i]) >= 0; i++) |
236 | input_set_abs_params(&guillemot->dev, t, 0, 255, 0, 0); | 243 | input_set_abs_params(input_dev, t, 0, 255, 0, 0); |
237 | 244 | ||
238 | if (guillemot->type->hat) { | 245 | if (guillemot->type->hat) { |
239 | input_set_abs_params(&guillemot->dev, ABS_HAT0X, -1, 1, 0, 0); | 246 | 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); | 247 | input_set_abs_params(input_dev, ABS_HAT0Y, -1, 1, 0, 0); |
241 | } | 248 | } |
242 | 249 | ||
243 | for (i = 0; (t = guillemot->type->btn[i]) >= 0; i++) | 250 | for (i = 0; (t = guillemot->type->btn[i]) >= 0; i++) |
244 | set_bit(t, guillemot->dev.keybit); | 251 | set_bit(t, input_dev->keybit); |
245 | 252 | ||
246 | input_register_device(&guillemot->dev); | 253 | 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 | 254 | ||
250 | return 0; | 255 | return 0; |
251 | 256 | ||
252 | fail2: gameport_close(gameport); | 257 | fail2: gameport_close(gameport); |
253 | fail1: gameport_set_drvdata(gameport, NULL); | 258 | fail1: gameport_set_drvdata(gameport, NULL); |
259 | input_free_device(input_dev); | ||
254 | kfree(guillemot); | 260 | kfree(guillemot); |
255 | return err; | 261 | return err; |
256 | } | 262 | } |
@@ -260,7 +266,7 @@ static void guillemot_disconnect(struct gameport *gameport) | |||
260 | struct guillemot *guillemot = gameport_get_drvdata(gameport); | 266 | struct guillemot *guillemot = gameport_get_drvdata(gameport); |
261 | 267 | ||
262 | printk(KERN_INFO "guillemot.c: Failed %d reads out of %d on %s\n", guillemot->reads, guillemot->bads, guillemot->phys); | 268 | 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); | 269 | input_unregister_device(guillemot->dev); |
264 | gameport_close(gameport); | 270 | gameport_close(gameport); |
265 | kfree(guillemot); | 271 | kfree(guillemot); |
266 | } | 272 | } |
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 | ||
340 | int iforce_init_device(struct iforce *iforce) | 341 | int 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); | |||
139 | static int mark_core_as_ready(struct iforce *iforce, unsigned short addr) | 139 | static 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 | ||
154 | void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data, struct pt_regs *regs) | 155 | void 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 | ||
119 | struct iforce { | 119 | struct 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..c4ed01758226 100644 --- a/drivers/input/joystick/interact.c +++ b/drivers/input/joystick/interact.c | |||
@@ -38,6 +38,7 @@ | |||
38 | #include <linux/init.h> | 38 | #include <linux/init.h> |
39 | #include <linux/gameport.h> | 39 | #include <linux/gameport.h> |
40 | #include <linux/input.h> | 40 | #include <linux/input.h> |
41 | #include <linux/jiffies.h> | ||
41 | 42 | ||
42 | #define DRIVER_DESC "InterAct digital joystick driver" | 43 | #define DRIVER_DESC "InterAct digital joystick driver" |
43 | 44 | ||
@@ -54,7 +55,7 @@ MODULE_LICENSE("GPL"); | |||
54 | 55 | ||
55 | struct interact { | 56 | struct interact { |
56 | struct gameport *gameport; | 57 | struct gameport *gameport; |
57 | struct input_dev dev; | 58 | struct input_dev *dev; |
58 | int bads; | 59 | int bads; |
59 | int reads; | 60 | int reads; |
60 | unsigned char type; | 61 | unsigned char type; |
@@ -130,7 +131,7 @@ static int interact_read_packet(struct gameport *gameport, int length, u32 *data | |||
130 | static void interact_poll(struct gameport *gameport) | 131 | static void interact_poll(struct gameport *gameport) |
131 | { | 132 | { |
132 | struct interact *interact = gameport_get_drvdata(gameport); | 133 | struct interact *interact = gameport_get_drvdata(gameport); |
133 | struct input_dev *dev = &interact->dev; | 134 | struct input_dev *dev = interact->dev; |
134 | u32 data[3]; | 135 | u32 data[3]; |
135 | int i; | 136 | int i; |
136 | 137 | ||
@@ -208,14 +209,20 @@ static void interact_close(struct input_dev *dev) | |||
208 | static int interact_connect(struct gameport *gameport, struct gameport_driver *drv) | 209 | static int interact_connect(struct gameport *gameport, struct gameport_driver *drv) |
209 | { | 210 | { |
210 | struct interact *interact; | 211 | struct interact *interact; |
212 | struct input_dev *input_dev; | ||
211 | __u32 data[3]; | 213 | __u32 data[3]; |
212 | int i, t; | 214 | int i, t; |
213 | int err; | 215 | int err; |
214 | 216 | ||
215 | if (!(interact = kzalloc(sizeof(struct interact), GFP_KERNEL))) | 217 | interact = kzalloc(sizeof(struct interact), GFP_KERNEL); |
216 | return -ENOMEM; | 218 | input_dev = input_allocate_device(); |
219 | if (!interact || !input_dev) { | ||
220 | err = -ENOMEM; | ||
221 | goto fail1; | ||
222 | } | ||
217 | 223 | ||
218 | interact->gameport = gameport; | 224 | interact->gameport = gameport; |
225 | interact->dev = input_dev; | ||
219 | 226 | ||
220 | gameport_set_drvdata(gameport, interact); | 227 | gameport_set_drvdata(gameport, interact); |
221 | 228 | ||
@@ -249,41 +256,40 @@ static int interact_connect(struct gameport *gameport, struct gameport_driver *d | |||
249 | interact->type = i; | 256 | interact->type = i; |
250 | interact->length = interact_type[i].length; | 257 | interact->length = interact_type[i].length; |
251 | 258 | ||
252 | interact->dev.private = interact; | 259 | input_dev->name = interact_type[i].name; |
253 | interact->dev.open = interact_open; | 260 | input_dev->phys = interact->phys; |
254 | interact->dev.close = interact_close; | 261 | input_dev->id.bustype = BUS_GAMEPORT; |
262 | input_dev->id.vendor = GAMEPORT_ID_VENDOR_INTERACT; | ||
263 | input_dev->id.product = interact_type[i].id; | ||
264 | input_dev->id.version = 0x0100; | ||
265 | input_dev->private = interact; | ||
255 | 266 | ||
256 | interact->dev.name = interact_type[i].name; | 267 | input_dev->open = interact_open; |
257 | interact->dev.phys = interact->phys; | 268 | 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 | 269 | ||
263 | interact->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); | 270 | input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); |
264 | 271 | ||
265 | for (i = 0; (t = interact_type[interact->type].abs[i]) >= 0; i++) { | 272 | for (i = 0; (t = interact_type[interact->type].abs[i]) >= 0; i++) { |
266 | set_bit(t, interact->dev.absbit); | 273 | set_bit(t, input_dev->absbit); |
267 | if (i < interact_type[interact->type].b8) { | 274 | if (i < interact_type[interact->type].b8) { |
268 | interact->dev.absmin[t] = 0; | 275 | input_dev->absmin[t] = 0; |
269 | interact->dev.absmax[t] = 255; | 276 | input_dev->absmax[t] = 255; |
270 | } else { | 277 | } else { |
271 | interact->dev.absmin[t] = -1; | 278 | input_dev->absmin[t] = -1; |
272 | interact->dev.absmax[t] = 1; | 279 | input_dev->absmax[t] = 1; |
273 | } | 280 | } |
274 | } | 281 | } |
275 | 282 | ||
276 | for (i = 0; (t = interact_type[interact->type].btn[i]) >= 0; i++) | 283 | for (i = 0; (t = interact_type[interact->type].btn[i]) >= 0; i++) |
277 | set_bit(t, interact->dev.keybit); | 284 | set_bit(t, input_dev->keybit); |
278 | 285 | ||
279 | input_register_device(&interact->dev); | 286 | input_register_device(interact->dev); |
280 | printk(KERN_INFO "input: %s on %s\n", | ||
281 | interact_type[interact->type].name, gameport->phys); | ||
282 | 287 | ||
283 | return 0; | 288 | return 0; |
284 | 289 | ||
285 | fail2: gameport_close(gameport); | 290 | fail2: gameport_close(gameport); |
286 | fail1: gameport_set_drvdata(gameport, NULL); | 291 | fail1: gameport_set_drvdata(gameport, NULL); |
292 | input_free_device(input_dev); | ||
287 | kfree(interact); | 293 | kfree(interact); |
288 | return err; | 294 | return err; |
289 | } | 295 | } |
@@ -292,7 +298,7 @@ static void interact_disconnect(struct gameport *gameport) | |||
292 | { | 298 | { |
293 | struct interact *interact = gameport_get_drvdata(gameport); | 299 | struct interact *interact = gameport_get_drvdata(gameport); |
294 | 300 | ||
295 | input_unregister_device(&interact->dev); | 301 | input_unregister_device(interact->dev); |
296 | gameport_close(gameport); | 302 | gameport_close(gameport); |
297 | gameport_set_drvdata(gameport, NULL); | 303 | gameport_set_drvdata(gameport, NULL); |
298 | kfree(interact); | 304 | kfree(interact); |
diff --git a/drivers/input/joystick/joydump.c b/drivers/input/joystick/joydump.c index 4234ccaf9146..88ec5a918f2e 100644 --- a/drivers/input/joystick/joydump.c +++ b/drivers/input/joystick/joydump.c | |||
@@ -34,6 +34,7 @@ | |||
34 | #include <linux/kernel.h> | 34 | #include <linux/kernel.h> |
35 | #include <linux/delay.h> | 35 | #include <linux/delay.h> |
36 | #include <linux/init.h> | 36 | #include <linux/init.h> |
37 | #include <linux/slab.h> | ||
37 | 38 | ||
38 | #define DRIVER_DESC "Gameport data dumper module" | 39 | #define DRIVER_DESC "Gameport data dumper module" |
39 | 40 | ||
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 | ||
50 | static int magellan_buttons[] = { BTN_0, BTN_1, BTN_2, BTN_3, BTN_4, BTN_5, BTN_6, BTN_7, BTN_8 }; | 50 | static int magellan_buttons[] = { BTN_0, BTN_1, BTN_2, BTN_3, BTN_4, BTN_5, BTN_6, BTN_7, BTN_8 }; |
51 | static int magellan_axes[] = { ABS_X, ABS_Y, ABS_Z, ABS_RX, ABS_RY, ABS_RZ }; | 51 | static int magellan_axes[] = { ABS_X, ABS_Y, ABS_Z, ABS_RX, ABS_RY, ABS_RZ }; |
52 | static char *magellan_name = "LogiCad3D Magellan / SpaceMouse"; | ||
53 | 52 | ||
54 | /* | 53 | /* |
55 | * Per-Magellan data. | 54 | * Per-Magellan data. |
56 | */ | 55 | */ |
57 | 56 | ||
58 | struct magellan { | 57 | struct 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 | ||
86 | static void magellan_process_packet(struct magellan* magellan, struct pt_regs *regs) | 85 | static 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) | |||
153 | static int magellan_connect(struct serio *serio, struct serio_driver *drv) | 152 | static 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..78dd163cd702 100644 --- a/drivers/input/joystick/sidewinder.c +++ b/drivers/input/joystick/sidewinder.c | |||
@@ -33,6 +33,7 @@ | |||
33 | #include <linux/init.h> | 33 | #include <linux/init.h> |
34 | #include <linux/input.h> | 34 | #include <linux/input.h> |
35 | #include <linux/gameport.h> | 35 | #include <linux/gameport.h> |
36 | #include <linux/jiffies.h> | ||
36 | 37 | ||
37 | #define DRIVER_DESC "Microsoft SideWinder joystick family driver" | 38 | #define DRIVER_DESC "Microsoft SideWinder joystick family driver" |
38 | 39 | ||
@@ -113,7 +114,7 @@ static struct { | |||
113 | 114 | ||
114 | struct sw { | 115 | struct sw { |
115 | struct gameport *gameport; | 116 | struct gameport *gameport; |
116 | struct input_dev dev[4]; | 117 | struct input_dev *dev[4]; |
117 | char name[64]; | 118 | char name[64]; |
118 | char phys[4][32]; | 119 | char phys[4][32]; |
119 | int length; | 120 | int length; |
@@ -301,7 +302,7 @@ static int sw_check(__u64 t) | |||
301 | static int sw_parse(unsigned char *buf, struct sw *sw) | 302 | static int sw_parse(unsigned char *buf, struct sw *sw) |
302 | { | 303 | { |
303 | int hat, i, j; | 304 | int hat, i, j; |
304 | struct input_dev *dev = sw->dev; | 305 | struct input_dev *dev; |
305 | 306 | ||
306 | switch (sw->type) { | 307 | switch (sw->type) { |
307 | 308 | ||
@@ -310,6 +311,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) | 311 | if (sw_check(GB(0,64)) || (hat = (GB(6,1) << 3) | GB(60,3)) > 8) |
311 | return -1; | 312 | return -1; |
312 | 313 | ||
314 | dev = sw->dev[0]; | ||
315 | |||
313 | input_report_abs(dev, ABS_X, (GB( 3,3) << 7) | GB(16,7)); | 316 | 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)); | 317 | 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)); | 318 | input_report_abs(dev, ABS_RZ, (GB(35,2) << 7) | GB(40,7)); |
@@ -335,13 +338,13 @@ static int sw_parse(unsigned char *buf, struct sw *sw) | |||
335 | if (sw_parity(GB(i*15,15))) | 338 | if (sw_parity(GB(i*15,15))) |
336 | return -1; | 339 | return -1; |
337 | 340 | ||
338 | input_report_abs(dev + i, ABS_X, GB(i*15+3,1) - GB(i*15+2,1)); | 341 | 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)); | 342 | input_report_abs(sw->dev[i], ABS_Y, GB(i*15+0,1) - GB(i*15+1,1)); |
340 | 343 | ||
341 | for (j = 0; j < 10; j++) | 344 | for (j = 0; j < 10; j++) |
342 | input_report_key(dev + i, sw_btn[SW_ID_GP][j], !GB(i*15+j+4,1)); | 345 | input_report_key(sw->dev[i], sw_btn[SW_ID_GP][j], !GB(i*15+j+4,1)); |
343 | 346 | ||
344 | input_sync(dev + i); | 347 | input_sync(sw->dev[i]); |
345 | } | 348 | } |
346 | 349 | ||
347 | return 0; | 350 | return 0; |
@@ -352,6 +355,7 @@ static int sw_parse(unsigned char *buf, struct sw *sw) | |||
352 | if (!sw_parity(GB(0,48)) || (hat = GB(42,4)) > 8) | 355 | if (!sw_parity(GB(0,48)) || (hat = GB(42,4)) > 8) |
353 | return -1; | 356 | return -1; |
354 | 357 | ||
358 | dev = sw->dev[0]; | ||
355 | input_report_abs(dev, ABS_X, GB( 9,10)); | 359 | input_report_abs(dev, ABS_X, GB( 9,10)); |
356 | input_report_abs(dev, ABS_Y, GB(19,10)); | 360 | input_report_abs(dev, ABS_Y, GB(19,10)); |
357 | input_report_abs(dev, ABS_RZ, GB(36, 6)); | 361 | input_report_abs(dev, ABS_RZ, GB(36, 6)); |
@@ -372,6 +376,7 @@ static int sw_parse(unsigned char *buf, struct sw *sw) | |||
372 | if (!sw_parity(GB(0,43)) || (hat = GB(28,4)) > 8) | 376 | if (!sw_parity(GB(0,43)) || (hat = GB(28,4)) > 8) |
373 | return -1; | 377 | return -1; |
374 | 378 | ||
379 | dev = sw->dev[0]; | ||
375 | input_report_abs(dev, ABS_X, GB( 0,10)); | 380 | input_report_abs(dev, ABS_X, GB( 0,10)); |
376 | input_report_abs(dev, ABS_Y, GB(16,10)); | 381 | input_report_abs(dev, ABS_Y, GB(16,10)); |
377 | input_report_abs(dev, ABS_THROTTLE, GB(32, 6)); | 382 | input_report_abs(dev, ABS_THROTTLE, GB(32, 6)); |
@@ -396,6 +401,7 @@ static int sw_parse(unsigned char *buf, struct sw *sw) | |||
396 | if (!sw_parity(GB(0,33))) | 401 | if (!sw_parity(GB(0,33))) |
397 | return -1; | 402 | return -1; |
398 | 403 | ||
404 | dev = sw->dev[0]; | ||
399 | input_report_abs(dev, ABS_RX, GB( 0,10)); | 405 | input_report_abs(dev, ABS_RX, GB( 0,10)); |
400 | input_report_abs(dev, ABS_RUDDER, GB(10, 6)); | 406 | input_report_abs(dev, ABS_RUDDER, GB(10, 6)); |
401 | input_report_abs(dev, ABS_THROTTLE, GB(16, 6)); | 407 | input_report_abs(dev, ABS_THROTTLE, GB(16, 6)); |
@@ -581,6 +587,7 @@ static int sw_guess_mode(unsigned char *buf, int len) | |||
581 | static int sw_connect(struct gameport *gameport, struct gameport_driver *drv) | 587 | static int sw_connect(struct gameport *gameport, struct gameport_driver *drv) |
582 | { | 588 | { |
583 | struct sw *sw; | 589 | struct sw *sw; |
590 | struct input_dev *input_dev; | ||
584 | int i, j, k, l; | 591 | int i, j, k, l; |
585 | int err; | 592 | int err; |
586 | unsigned char *buf = NULL; /* [SW_LENGTH] */ | 593 | unsigned char *buf = NULL; /* [SW_LENGTH] */ |
@@ -729,42 +736,50 @@ static int sw_connect(struct gameport *gameport, struct gameport_driver *drv) | |||
729 | sprintf(sw->name, "Microsoft SideWinder %s", sw_name[sw->type]); | 736 | sprintf(sw->name, "Microsoft SideWinder %s", sw_name[sw->type]); |
730 | sprintf(sw->phys[i], "%s/input%d", gameport->phys, i); | 737 | sprintf(sw->phys[i], "%s/input%d", gameport->phys, i); |
731 | 738 | ||
732 | sw->dev[i].private = sw; | 739 | input_dev = input_allocate_device(); |
740 | if (!input_dev) { | ||
741 | err = -ENOMEM; | ||
742 | goto fail3; | ||
743 | } | ||
733 | 744 | ||
734 | sw->dev[i].open = sw_open; | 745 | input_dev->name = sw->name; |
735 | sw->dev[i].close = sw_close; | 746 | input_dev->phys = sw->phys[i]; |
747 | input_dev->id.bustype = BUS_GAMEPORT; | ||
748 | input_dev->id.vendor = GAMEPORT_ID_VENDOR_MICROSOFT; | ||
749 | input_dev->id.product = sw->type; | ||
750 | input_dev->id.version = 0x0100; | ||
751 | input_dev->cdev.dev = &gameport->dev; | ||
752 | input_dev->private = sw; | ||
736 | 753 | ||
737 | sw->dev[i].name = sw->name; | 754 | input_dev->open = sw_open; |
738 | sw->dev[i].phys = sw->phys[i]; | 755 | 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 | 756 | ||
744 | sw->dev[i].evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); | 757 | input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); |
745 | 758 | ||
746 | for (j = 0; (bits = sw_bit[sw->type][j]); j++) { | 759 | for (j = 0; (bits = sw_bit[sw->type][j]); j++) { |
747 | code = sw_abs[sw->type][j]; | 760 | code = sw_abs[sw->type][j]; |
748 | set_bit(code, sw->dev[i].absbit); | 761 | set_bit(code, input_dev->absbit); |
749 | sw->dev[i].absmax[code] = (1 << bits) - 1; | 762 | input_dev->absmax[code] = (1 << bits) - 1; |
750 | sw->dev[i].absmin[code] = (bits == 1) ? -1 : 0; | 763 | input_dev->absmin[code] = (bits == 1) ? -1 : 0; |
751 | sw->dev[i].absfuzz[code] = ((bits >> 1) >= 2) ? (1 << ((bits >> 1) - 2)) : 0; | 764 | input_dev->absfuzz[code] = ((bits >> 1) >= 2) ? (1 << ((bits >> 1) - 2)) : 0; |
752 | if (code != ABS_THROTTLE) | 765 | if (code != ABS_THROTTLE) |
753 | sw->dev[i].absflat[code] = (bits >= 5) ? (1 << (bits - 5)) : 0; | 766 | input_dev->absflat[code] = (bits >= 5) ? (1 << (bits - 5)) : 0; |
754 | } | 767 | } |
755 | 768 | ||
756 | for (j = 0; (code = sw_btn[sw->type][j]); j++) | 769 | for (j = 0; (code = sw_btn[sw->type][j]); j++) |
757 | set_bit(code, sw->dev[i].keybit); | 770 | set_bit(code, input_dev->keybit); |
771 | |||
772 | dbg("%s%s [%d-bit id %d data %d]\n", sw->name, comment, m, l, k); | ||
758 | 773 | ||
759 | input_register_device(sw->dev + i); | 774 | 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 | } | 775 | } |
763 | 776 | ||
764 | return 0; | 777 | return 0; |
765 | 778 | ||
766 | fail2: gameport_close(gameport); | 779 | fail3: while (--i >= 0) |
767 | fail1: gameport_set_drvdata(gameport, NULL); | 780 | input_unregister_device(sw->dev[i]); |
781 | fail2: gameport_close(gameport); | ||
782 | fail1: gameport_set_drvdata(gameport, NULL); | ||
768 | kfree(sw); | 783 | kfree(sw); |
769 | kfree(buf); | 784 | kfree(buf); |
770 | kfree(idbuf); | 785 | kfree(idbuf); |
@@ -777,7 +792,7 @@ static void sw_disconnect(struct gameport *gameport) | |||
777 | int i; | 792 | int i; |
778 | 793 | ||
779 | for (i = 0; i < sw->number; i++) | 794 | for (i = 0; i < sw->number; i++) |
780 | input_unregister_device(sw->dev + i); | 795 | input_unregister_device(sw->dev[i]); |
781 | gameport_close(gameport); | 796 | gameport_close(gameport); |
782 | gameport_set_drvdata(gameport, NULL); | 797 | gameport_set_drvdata(gameport, NULL); |
783 | kfree(sw); | 798 | 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 | ||
72 | struct spaceball { | 72 | struct 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 | ||
86 | static void spaceball_process_packet(struct spaceball* spaceball, struct pt_regs *regs) | 85 | static 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) | |||
208 | static int spaceball_connect(struct serio *serio, struct serio_driver *drv) | 207 | static 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 | ||
53 | static int spaceorb_buttons[] = { BTN_TL, BTN_TR, BTN_Y, BTN_X, BTN_B, BTN_A }; | 53 | static int spaceorb_buttons[] = { BTN_TL, BTN_TR, BTN_Y, BTN_X, BTN_B, BTN_A }; |
54 | static int spaceorb_axes[] = { ABS_X, ABS_Y, ABS_Z, ABS_RX, ABS_RY, ABS_RZ }; | 54 | static int spaceorb_axes[] = { ABS_X, ABS_Y, ABS_Z, ABS_RX, ABS_RY, ABS_RZ }; |
55 | static char *spaceorb_name = "SpaceTec SpaceOrb 360 / Avenger"; | ||
56 | 55 | ||
57 | /* | 56 | /* |
58 | * Per-Orb data. | 57 | * Per-Orb data. |
59 | */ | 58 | */ |
60 | 59 | ||
61 | struct spaceorb { | 60 | struct 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 | ||
79 | static void spaceorb_process_packet(struct spaceorb *spaceorb, struct pt_regs *regs) | 77 | static 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) | |||
169 | static int spaceorb_connect(struct serio *serio, struct serio_driver *drv) | 167 | static 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 | ||
51 | static char *stinger_name = "Gravis Stinger"; | ||
52 | |||
53 | /* | 51 | /* |
54 | * Per-Stinger data. | 52 | * Per-Stinger data. |
55 | */ | 53 | */ |
56 | 54 | ||
57 | struct stinger { | 55 | struct 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 | ||
69 | static void stinger_process_packet(struct stinger *stinger, struct pt_regs *regs) | 67 | static 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) | |||
141 | static int stinger_connect(struct serio *serio, struct serio_driver *drv) | 139 | static 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..60e2aac7d06e 100644 --- a/drivers/input/joystick/tmdc.c +++ b/drivers/input/joystick/tmdc.c | |||
@@ -38,6 +38,7 @@ | |||
38 | #include <linux/init.h> | 38 | #include <linux/init.h> |
39 | #include <linux/gameport.h> | 39 | #include <linux/gameport.h> |
40 | #include <linux/input.h> | 40 | #include <linux/input.h> |
41 | #include <linux/jiffies.h> | ||
41 | 42 | ||
42 | #define DRIVER_DESC "ThrustMaster DirectConnect joystick driver" | 43 | #define DRIVER_DESC "ThrustMaster DirectConnect joystick driver" |
43 | 44 | ||
@@ -63,37 +64,70 @@ MODULE_LICENSE("GPL"); | |||
63 | #define TMDC_ABS_HAT 4 | 64 | #define TMDC_ABS_HAT 4 |
64 | #define TMDC_BTN 16 | 65 | #define TMDC_BTN 16 |
65 | 66 | ||
66 | static unsigned char tmdc_byte_a[16] = { 0, 1, 3, 4, 6, 7 }; | 67 | static const unsigned char tmdc_byte_a[16] = { 0, 1, 3, 4, 6, 7 }; |
67 | static unsigned char tmdc_byte_d[16] = { 2, 5, 8, 9 }; | 68 | static const unsigned char tmdc_byte_d[16] = { 2, 5, 8, 9 }; |
68 | 69 | ||
69 | static signed char tmdc_abs[TMDC_ABS] = | 70 | static const signed char tmdc_abs[TMDC_ABS] = |
70 | { ABS_X, ABS_Y, ABS_RUDDER, ABS_THROTTLE, ABS_RX, ABS_RY, ABS_RZ }; | 71 | { ABS_X, ABS_Y, ABS_RUDDER, ABS_THROTTLE, ABS_RX, ABS_RY, ABS_RZ }; |
71 | static signed char tmdc_abs_hat[TMDC_ABS_HAT] = | 72 | static const signed char tmdc_abs_hat[TMDC_ABS_HAT] = |
72 | { ABS_HAT0X, ABS_HAT0Y, ABS_HAT1X, ABS_HAT1Y }; | 73 | { ABS_HAT0X, ABS_HAT0Y, ABS_HAT1X, ABS_HAT1Y }; |
73 | static signed char tmdc_abs_at[TMDC_ABS] = | 74 | static const signed char tmdc_abs_at[TMDC_ABS] = |
74 | { ABS_X, ABS_Y, ABS_RUDDER, -1, ABS_THROTTLE }; | 75 | { ABS_X, ABS_Y, ABS_RUDDER, -1, ABS_THROTTLE }; |
75 | static signed char tmdc_abs_fm[TMDC_ABS] = | 76 | static const signed char tmdc_abs_fm[TMDC_ABS] = |
76 | { ABS_RX, ABS_RY, ABS_X, ABS_Y }; | 77 | { ABS_RX, ABS_RY, ABS_X, ABS_Y }; |
77 | 78 | ||
78 | static short tmdc_btn_pad[TMDC_BTN] = | 79 | static 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 }; | 80 | { BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_START, BTN_SELECT, BTN_TL, BTN_TR }; |
80 | static short tmdc_btn_joy[TMDC_BTN] = | 81 | static const short tmdc_btn_joy[TMDC_BTN] = |
81 | { BTN_TRIGGER, BTN_THUMB, BTN_TOP, BTN_TOP2, BTN_BASE, BTN_BASE2, BTN_THUMB2, BTN_PINKIE, | 82 | { 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 }; | 83 | BTN_BASE3, BTN_BASE4, BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z }; |
83 | static short tmdc_btn_fm[TMDC_BTN] = | 84 | static 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 }; | 85 | { BTN_TRIGGER, BTN_C, BTN_B, BTN_A, BTN_THUMB, BTN_X, BTN_Y, BTN_Z, BTN_TOP, BTN_TOP2 }; |
85 | static short tmdc_btn_at[TMDC_BTN] = | 86 | static const short tmdc_btn_at[TMDC_BTN] = |
86 | { BTN_TRIGGER, BTN_THUMB2, BTN_PINKIE, BTN_THUMB, BTN_BASE6, BTN_BASE5, BTN_BASE4, | 87 | { BTN_TRIGGER, BTN_THUMB2, BTN_PINKIE, BTN_THUMB, BTN_BASE6, BTN_BASE5, BTN_BASE4, |
87 | BTN_BASE3, BTN_BASE2, BTN_BASE }; | 88 | BTN_BASE3, BTN_BASE2, BTN_BASE }; |
88 | 89 | ||
89 | static struct { | 90 | static const struct { |
90 | int x; | 91 | int x; |
91 | int y; | 92 | int y; |
92 | } tmdc_hat_to_axis[] = {{ 0, 0}, { 1, 0}, { 0,-1}, {-1, 0}, { 0, 1}}; | 93 | } tmdc_hat_to_axis[] = {{ 0, 0}, { 1, 0}, { 0,-1}, {-1, 0}, { 0, 1}}; |
93 | 94 | ||
95 | static const struct tmdc_model { | ||
96 | unsigned char id; | ||
97 | const char *name; | ||
98 | char abs; | ||
99 | char hats; | ||
100 | char btnc[4]; | ||
101 | char btno[4]; | ||
102 | const signed char *axes; | ||
103 | const short *buttons; | ||
104 | } tmdc_models[] = { | ||
105 | { 1, "ThrustMaster Millenium 3D Inceptor", 6, 2, { 4, 2 }, { 4, 6 }, tmdc_abs, tmdc_btn_joy }, | ||
106 | { 3, "ThrustMaster Rage 3D Gamepad", 2, 0, { 8, 2 }, { 0, 0 }, tmdc_abs, tmdc_btn_pad }, | ||
107 | { 4, "ThrustMaster Attack Throttle", 5, 2, { 4, 6 }, { 4, 2 }, tmdc_abs_at, tmdc_btn_at }, | ||
108 | { 8, "ThrustMaster FragMaster", 4, 0, { 8, 2 }, { 0, 0 }, tmdc_abs_fm, tmdc_btn_fm }, | ||
109 | { 163, "Thrustmaster Fusion GamePad", 2, 0, { 8, 2 }, { 0, 0 }, tmdc_abs, tmdc_btn_pad }, | ||
110 | { 0, "Unknown %d-axis, %d-button TM device %d", 0, 0, { 0, 0 }, { 0, 0 }, tmdc_abs, tmdc_btn_joy } | ||
111 | }; | ||
112 | |||
113 | |||
114 | struct tmdc_port { | ||
115 | struct input_dev *dev; | ||
116 | char name[64]; | ||
117 | char phys[32]; | ||
118 | int mode; | ||
119 | const signed char *abs; | ||
120 | const short *btn; | ||
121 | unsigned char absc; | ||
122 | unsigned char btnc[4]; | ||
123 | unsigned char btno[4]; | ||
124 | }; | ||
125 | |||
94 | struct tmdc { | 126 | struct tmdc { |
95 | struct gameport *gameport; | 127 | struct gameport *gameport; |
96 | struct input_dev dev[2]; | 128 | struct tmdc_port *port[2]; |
129 | #if 0 | ||
130 | struct input_dev *dev[2]; | ||
97 | char name[2][64]; | 131 | char name[2][64]; |
98 | char phys[2][32]; | 132 | char phys[2][32]; |
99 | int mode[2]; | 133 | int mode[2]; |
@@ -102,6 +136,7 @@ struct tmdc { | |||
102 | unsigned char absc[2]; | 136 | unsigned char absc[2]; |
103 | unsigned char btnc[2][4]; | 137 | unsigned char btnc[2][4]; |
104 | unsigned char btno[2][4]; | 138 | unsigned char btno[2][4]; |
139 | #endif | ||
105 | int reads; | 140 | int reads; |
106 | int bads; | 141 | int bads; |
107 | unsigned char exists; | 142 | unsigned char exists; |
@@ -156,6 +191,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); | 191 | return (i[0] == TMDC_MAX_LENGTH) | ((i[1] == TMDC_MAX_LENGTH) << 1); |
157 | } | 192 | } |
158 | 193 | ||
194 | static int tmdc_parse_packet(struct tmdc_port *port, unsigned char *data) | ||
195 | { | ||
196 | int i, k, l; | ||
197 | |||
198 | if (data[TMDC_BYTE_ID] != port->mode) | ||
199 | return -1; | ||
200 | |||
201 | for (i = 0; i < port->absc; i++) { | ||
202 | if (port->abs[i] < 0) | ||
203 | return 0; | ||
204 | |||
205 | input_report_abs(port->dev, port->abs[i], data[tmdc_byte_a[i]]); | ||
206 | } | ||
207 | |||
208 | switch (port->mode) { | ||
209 | |||
210 | case TMDC_MODE_M3DI: | ||
211 | |||
212 | i = tmdc_byte_d[0]; | ||
213 | input_report_abs(port->dev, ABS_HAT0X, ((data[i] >> 3) & 1) - ((data[i] >> 1) & 1)); | ||
214 | input_report_abs(port->dev, ABS_HAT0Y, ((data[i] >> 2) & 1) - ( data[i] & 1)); | ||
215 | break; | ||
216 | |||
217 | case TMDC_MODE_AT: | ||
218 | |||
219 | i = tmdc_byte_a[3]; | ||
220 | input_report_abs(port->dev, ABS_HAT0X, tmdc_hat_to_axis[(data[i] - 141) / 25].x); | ||
221 | input_report_abs(port->dev, ABS_HAT0Y, tmdc_hat_to_axis[(data[i] - 141) / 25].y); | ||
222 | break; | ||
223 | |||
224 | } | ||
225 | |||
226 | for (k = l = 0; k < 4; k++) { | ||
227 | for (i = 0; i < port->btnc[k]; i++) | ||
228 | input_report_key(port->dev, port->btn[i + l], | ||
229 | ((data[tmdc_byte_d[k]] >> (i + port->btno[k])) & 1)); | ||
230 | l += port->btnc[k]; | ||
231 | } | ||
232 | |||
233 | input_sync(port->dev); | ||
234 | |||
235 | return 0; | ||
236 | } | ||
237 | |||
159 | /* | 238 | /* |
160 | * tmdc_poll() reads and analyzes ThrustMaster joystick data. | 239 | * tmdc_poll() reads and analyzes ThrustMaster joystick data. |
161 | */ | 240 | */ |
@@ -164,57 +243,21 @@ static void tmdc_poll(struct gameport *gameport) | |||
164 | { | 243 | { |
165 | unsigned char data[2][TMDC_MAX_LENGTH]; | 244 | unsigned char data[2][TMDC_MAX_LENGTH]; |
166 | struct tmdc *tmdc = gameport_get_drvdata(gameport); | 245 | struct tmdc *tmdc = gameport_get_drvdata(gameport); |
167 | struct input_dev *dev; | ||
168 | unsigned char r, bad = 0; | 246 | unsigned char r, bad = 0; |
169 | int i, j, k, l; | 247 | int i; |
170 | 248 | ||
171 | tmdc->reads++; | 249 | tmdc->reads++; |
172 | 250 | ||
173 | if ((r = tmdc_read_packet(tmdc->gameport, data)) != tmdc->exists) | 251 | if ((r = tmdc_read_packet(tmdc->gameport, data)) != tmdc->exists) |
174 | bad = 1; | 252 | bad = 1; |
175 | else | 253 | else { |
176 | 254 | for (i = 0; i < 2; i++) { | |
177 | for (j = 0; j < 2; j++) | 255 | 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 | 256 | ||
194 | case TMDC_MODE_M3DI: | 257 | if (tmdc_parse_packet(tmdc->port[i], data[i])) |
195 | 258 | 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 | } | 259 | } |
216 | 260 | } | |
217 | input_sync(dev); | ||
218 | } | 261 | } |
219 | 262 | ||
220 | tmdc->bads += bad; | 263 | tmdc->bads += bad; |
@@ -235,31 +278,89 @@ static void tmdc_close(struct input_dev *dev) | |||
235 | gameport_stop_polling(tmdc->gameport); | 278 | gameport_stop_polling(tmdc->gameport); |
236 | } | 279 | } |
237 | 280 | ||
281 | static int tmdc_setup_port(struct tmdc *tmdc, int idx, unsigned char *data) | ||
282 | { | ||
283 | const struct tmdc_model *model; | ||
284 | struct tmdc_port *port; | ||
285 | struct input_dev *input_dev; | ||
286 | int i, j, b = 0; | ||
287 | |||
288 | tmdc->port[idx] = port = kzalloc(sizeof (struct tmdc_port), GFP_KERNEL); | ||
289 | input_dev = input_allocate_device(); | ||
290 | if (!port || !input_dev) { | ||
291 | kfree(port); | ||
292 | input_free_device(input_dev); | ||
293 | return -ENOMEM; | ||
294 | } | ||
295 | |||
296 | port->mode = data[TMDC_BYTE_ID]; | ||
297 | |||
298 | for (model = tmdc_models; model->id && model->id != port->mode; model++) | ||
299 | /* empty */; | ||
300 | |||
301 | port->abs = model->axes; | ||
302 | port->btn = model->buttons; | ||
303 | |||
304 | if (!model->id) { | ||
305 | port->absc = data[TMDC_BYTE_DEF] >> 4; | ||
306 | for (i = 0; i < 4; i++) | ||
307 | port->btnc[i] = i < (data[TMDC_BYTE_DEF] & 0xf) ? 8 : 0; | ||
308 | } else { | ||
309 | port->absc = model->abs; | ||
310 | for (i = 0; i < 4; i++) | ||
311 | port->btnc[i] = model->btnc[i]; | ||
312 | } | ||
313 | |||
314 | for (i = 0; i < 4; i++) | ||
315 | port->btno[i] = model->btno[i]; | ||
316 | |||
317 | snprintf(port->name, sizeof(port->name), model->name, | ||
318 | port->absc, (data[TMDC_BYTE_DEF] & 0xf) << 3, port->mode); | ||
319 | snprintf(port->phys, sizeof(port->phys), "%s/input%d", tmdc->gameport->phys, i); | ||
320 | |||
321 | port->dev = input_dev; | ||
322 | |||
323 | input_dev->name = port->name; | ||
324 | input_dev->phys = port->phys; | ||
325 | input_dev->id.bustype = BUS_GAMEPORT; | ||
326 | input_dev->id.vendor = GAMEPORT_ID_VENDOR_THRUSTMASTER; | ||
327 | input_dev->id.product = model->id; | ||
328 | input_dev->id.version = 0x0100; | ||
329 | input_dev->cdev.dev = &tmdc->gameport->dev; | ||
330 | input_dev->private = tmdc; | ||
331 | |||
332 | input_dev->open = tmdc_open; | ||
333 | input_dev->close = tmdc_close; | ||
334 | |||
335 | input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); | ||
336 | |||
337 | for (i = 0; i < port->absc && i < TMDC_ABS; i++) | ||
338 | if (port->abs[i] >= 0) | ||
339 | input_set_abs_params(input_dev, port->abs[i], 8, 248, 2, 4); | ||
340 | |||
341 | for (i = 0; i < model->hats && i < TMDC_ABS_HAT; i++) | ||
342 | input_set_abs_params(input_dev, tmdc_abs_hat[i], -1, 1, 0, 0); | ||
343 | |||
344 | for (i = 0; i < 4; i++) { | ||
345 | for (j = 0; j < port->btnc[i] && j < TMDC_BTN; j++) | ||
346 | set_bit(port->btn[j + b], input_dev->keybit); | ||
347 | b += port->btnc[i]; | ||
348 | } | ||
349 | |||
350 | input_register_device(port->dev); | ||
351 | |||
352 | return 0; | ||
353 | } | ||
354 | |||
238 | /* | 355 | /* |
239 | * tmdc_probe() probes for ThrustMaster type joysticks. | 356 | * tmdc_probe() probes for ThrustMaster type joysticks. |
240 | */ | 357 | */ |
241 | 358 | ||
242 | static int tmdc_connect(struct gameport *gameport, struct gameport_driver *drv) | 359 | static int tmdc_connect(struct gameport *gameport, struct gameport_driver *drv) |
243 | { | 360 | { |
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]; | 361 | unsigned char data[2][TMDC_MAX_LENGTH]; |
261 | struct tmdc *tmdc; | 362 | struct tmdc *tmdc; |
262 | int i, j, k, l, m; | 363 | int i; |
263 | int err; | 364 | int err; |
264 | 365 | ||
265 | if (!(tmdc = kzalloc(sizeof(struct tmdc), GFP_KERNEL))) | 366 | if (!(tmdc = kzalloc(sizeof(struct tmdc), GFP_KERNEL))) |
@@ -281,68 +382,25 @@ static int tmdc_connect(struct gameport *gameport, struct gameport_driver *drv) | |||
281 | gameport_set_poll_handler(gameport, tmdc_poll); | 382 | gameport_set_poll_handler(gameport, tmdc_poll); |
282 | gameport_set_poll_interval(gameport, 20); | 383 | gameport_set_poll_interval(gameport, 20); |
283 | 384 | ||
284 | for (j = 0; j < 2; j++) | 385 | for (i = 0; i < 2; i++) { |
285 | if (tmdc->exists & (1 << j)) { | 386 | if (tmdc->exists & (1 << i)) { |
286 | 387 | ||
287 | tmdc->mode[j] = data[j][TMDC_BYTE_ID]; | 388 | err = tmdc_setup_port(tmdc, i, data[i]); |
288 | 389 | if (err) | |
289 | for (m = 0; models[m].id && models[m].id != tmdc->mode[j]; m++); | 390 | 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 | } | 391 | } |
392 | } | ||
341 | 393 | ||
342 | return 0; | 394 | return 0; |
343 | 395 | ||
344 | fail2: gameport_close(gameport); | 396 | fail3: while (--i >= 0) { |
345 | fail1: gameport_set_drvdata(gameport, NULL); | 397 | if (tmdc->port[i]) { |
398 | input_unregister_device(tmdc->port[i]->dev); | ||
399 | kfree(tmdc->port[i]); | ||
400 | } | ||
401 | } | ||
402 | fail2: gameport_close(gameport); | ||
403 | fail1: gameport_set_drvdata(gameport, NULL); | ||
346 | kfree(tmdc); | 404 | kfree(tmdc); |
347 | return err; | 405 | return err; |
348 | } | 406 | } |
@@ -352,9 +410,12 @@ static void tmdc_disconnect(struct gameport *gameport) | |||
352 | struct tmdc *tmdc = gameport_get_drvdata(gameport); | 410 | struct tmdc *tmdc = gameport_get_drvdata(gameport); |
353 | int i; | 411 | int i; |
354 | 412 | ||
355 | for (i = 0; i < 2; i++) | 413 | for (i = 0; i < 2; i++) { |
356 | if (tmdc->exists & (1 << i)) | 414 | if (tmdc->port[i]) { |
357 | input_unregister_device(tmdc->dev + i); | 415 | input_unregister_device(tmdc->port[i]->dev); |
416 | kfree(tmdc->port[i]); | ||
417 | } | ||
418 | } | ||
358 | gameport_close(gameport); | 419 | gameport_close(gameport); |
359 | gameport_set_drvdata(gameport, NULL); | 420 | gameport_set_drvdata(gameport, NULL); |
360 | kfree(tmdc); | 421 | 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>"); | |||
42 | MODULE_DESCRIPTION("TurboGraFX parallel port interface driver"); | 42 | MODULE_DESCRIPTION("TurboGraFX parallel port interface driver"); |
43 | MODULE_LICENSE("GPL"); | 43 | MODULE_LICENSE("GPL"); |
44 | 44 | ||
45 | static int tgfx[] __initdata = { -1, 0, 0, 0, 0, 0, 0, 0 }; | 45 | #define TGFX_MAX_PORTS 3 |
46 | static int tgfx_nargs __initdata = 0; | 46 | #define TGFX_MAX_DEVICES 7 |
47 | module_param_array_named(map, tgfx, int, &tgfx_nargs, 0); | ||
48 | MODULE_PARM_DESC(map, "Describes first set of devices (<parport#>,<js1>,<js2>,..<js7>"); | ||
49 | 47 | ||
50 | static int tgfx_2[] __initdata = { -1, 0, 0, 0, 0, 0, 0, 0 }; | 48 | struct tgfx_config { |
51 | static int tgfx_nargs_2 __initdata = 0; | 49 | int args[TGFX_MAX_DEVICES + 1]; |
52 | module_param_array_named(map2, tgfx_2, int, &tgfx_nargs_2, 0); | 50 | int nargs; |
53 | MODULE_PARM_DESC(map2, "Describes second set of devices"); | 51 | }; |
52 | |||
53 | static struct tgfx_config tgfx[TGFX_MAX_PORTS] __initdata; | ||
54 | 54 | ||
55 | static int tgfx_3[] __initdata = { -1, 0, 0, 0, 0, 0, 0, 0 }; | 55 | module_param_array_named(map, tgfx[0].args, int, &tgfx[0].nargs, 0); |
56 | static int tgfx_nargs_3 __initdata = 0; | 56 | MODULE_PARM_DESC(map, "Describes first set of devices (<parport#>,<js1>,<js2>,..<js7>"); |
57 | module_param_array_named(map3, tgfx_3, int, &tgfx_nargs_3, 0); | 57 | module_param_array_named(map2, tgfx[1].args, int, &tgfx[1].nargs, 0); |
58 | MODULE_PARM_DESC(map2, "Describes second set of devices"); | ||
59 | module_param_array_named(map3, tgfx[2].args, int, &tgfx[2].nargs, 0); | ||
58 | MODULE_PARM_DESC(map3, "Describes third set of devices"); | 60 | MODULE_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 | ||
77 | static int tgfx_buttons[] = { BTN_TRIGGER, BTN_THUMB, BTN_THUMB2, BTN_TOP, BTN_TOP2 }; | 79 | static int tgfx_buttons[] = { BTN_TRIGGER, BTN_THUMB, BTN_THUMB2, BTN_TOP, BTN_TOP2 }; |
78 | static char *tgfx_name = "TurboGraFX Multisystem joystick"; | ||
79 | 80 | ||
80 | static struct tgfx { | 81 | static 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 | ||
160 | static struct tgfx __init *tgfx_probe(int *config, int nargs) | 164 | static 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 | |||
265 | static 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 | ||
245 | static int __init tgfx_init(void) | 276 | static 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 | ||
257 | static void __exit tgfx_exit(void) | 310 | static 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 | ||
270 | module_init(tgfx_init); | 319 | module_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 | ||
72 | static char *twidjoy_name = "Handykey Twiddler"; | ||
73 | |||
74 | static struct twidjoy_button_spec { | 72 | static 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 | ||
97 | struct twidjoy { | 95 | struct 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 | ||
109 | static void twidjoy_process_packet(struct twidjoy *twidjoy, struct pt_regs *regs) | 107 | static 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 |
49 | static char warrior_lengths[] = { 0, 4, 12, 3, 4, 4, 0, 0 }; | 49 | static char warrior_lengths[] = { 0, 4, 12, 3, 4, 4, 0, 0 }; |
50 | static char *warrior_name = "Logitech WingMan Warrior"; | ||
51 | 50 | ||
52 | /* | 51 | /* |
53 | * Per-Warrior data. | 52 | * Per-Warrior data. |
54 | */ | 53 | */ |
55 | 54 | ||
56 | struct warrior { | 55 | struct 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 | ||
68 | static void warrior_process_packet(struct warrior *warrior, struct pt_regs *regs) | 67 | static 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) | |||
146 | static int warrior_connect(struct serio *serio, struct serio_driver *drv) | 145 | static 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 | /* |