aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/joystick/analog.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/input/joystick/analog.c')
-rw-r--r--drivers/input/joystick/analog.c97
1 files changed, 44 insertions, 53 deletions
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
111static unsigned char analog_chf[] = { 0xf, 0x0, 0x1, 0x9, 0x2, 0x4, 0xc, 0x8, 0x3, 0x5, 0xb, 0x7, 0xd, 0xe, 0xa, 0x6 }; 112static unsigned char analog_chf[] = { 0xf, 0x0, 0x1, 0x9, 0x2, 0x4, 0xc, 0x8, 0x3, 0x5, 0xb, 0x7, 0xd, 0xe, 0xa, 0x6 };
112 113
113struct analog { 114struct 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
183static void analog_decode(struct analog *analog, int *axes, int *initial, int buttons) 184static 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
431static void analog_init_device(struct analog_port *port, struct analog *analog, int index) 432static 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
685static void analog_disconnect(struct gameport *gameport) 676static 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",