X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=drivers%2Finput%2Fjoystick%2Fwarrior.c;h=29d339acf4307b451087c2b93831adee544648f1;hb=refs%2Fheads%2Fvserver;hp=53d535bd1b59f48726d5728fdc9a83cba4603823;hpb=6a77f38946aaee1cd85eeec6cf4229b204c15071;p=linux-2.6.git diff --git a/drivers/input/joystick/warrior.c b/drivers/input/joystick/warrior.c index 53d535bd1..29d339acf 100644 --- a/drivers/input/joystick/warrior.c +++ b/drivers/input/joystick/warrior.c @@ -47,14 +47,13 @@ MODULE_LICENSE("GPL"); #define WARRIOR_MAX_LENGTH 16 static char warrior_lengths[] = { 0, 4, 12, 3, 4, 4, 0, 0 }; -static char *warrior_name = "Logitech WingMan Warrior"; /* * Per-Warrior data. */ struct warrior { - struct input_dev dev; + struct input_dev *dev; int idx, len; unsigned char data[WARRIOR_MAX_LENGTH]; char phys[32]; @@ -65,15 +64,13 @@ struct warrior { * Warrior. It updates the data accordingly. */ -static void warrior_process_packet(struct warrior *warrior, struct pt_regs *regs) +static void warrior_process_packet(struct warrior *warrior) { - struct input_dev *dev = &warrior->dev; + struct input_dev *dev = warrior->dev; unsigned char *data = warrior->data; if (!warrior->idx) return; - input_regs(dev, regs); - switch ((data[0] >> 4) & 7) { case 1: /* Button data */ input_report_key(dev, BTN_TRIGGER, data[3] & 1); @@ -102,12 +99,12 @@ static void warrior_process_packet(struct warrior *warrior, struct pt_regs *regs */ static irqreturn_t warrior_interrupt(struct serio *serio, - unsigned char data, unsigned int flags, struct pt_regs *regs) + unsigned char data, unsigned int flags) { - struct warrior* warrior = serio->private; + struct warrior *warrior = serio_get_drvdata(serio); if (data & 0x80) { - if (warrior->idx) warrior_process_packet(warrior, regs); + if (warrior->idx) warrior_process_packet(warrior); warrior->idx = 0; warrior->len = warrior_lengths[(data >> 4) & 7]; } @@ -116,7 +113,7 @@ static irqreturn_t warrior_interrupt(struct serio *serio, warrior->data[warrior->idx++] = data; if (warrior->idx == warrior->len) { - if (warrior->idx) warrior_process_packet(warrior, regs); + if (warrior->idx) warrior_process_packet(warrior); warrior->idx = 0; warrior->len = 0; } @@ -129,9 +126,11 @@ static irqreturn_t warrior_interrupt(struct serio *serio, static void warrior_disconnect(struct serio *serio) { - struct warrior* warrior = serio->private; - input_unregister_device(&warrior->dev); + struct warrior *warrior = serio_get_drvdata(serio); + serio_close(serio); + serio_set_drvdata(serio, NULL); + input_unregister_device(warrior->dev); kfree(warrior); } @@ -141,72 +140,79 @@ static void warrior_disconnect(struct serio *serio) * it as an input device. */ -static void warrior_connect(struct serio *serio, struct serio_driver *drv) +static int warrior_connect(struct serio *serio, struct serio_driver *drv) { struct warrior *warrior; - int i; - - if (serio->type != (SERIO_RS232 | SERIO_WARRIOR)) - return; - - if (!(warrior = kmalloc(sizeof(struct warrior), GFP_KERNEL))) - return; - - memset(warrior, 0, sizeof(struct warrior)); - - warrior->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REL) | BIT(EV_ABS); - warrior->dev.keybit[LONG(BTN_TRIGGER)] = BIT(BTN_TRIGGER) | BIT(BTN_THUMB) | BIT(BTN_TOP) | BIT(BTN_TOP2); - warrior->dev.relbit[0] = BIT(REL_DIAL); - warrior->dev.absbit[0] = BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_THROTTLE) | BIT(ABS_HAT0X) | BIT(ABS_HAT0Y); - - sprintf(warrior->phys, "%s/input0", serio->phys); - - init_input_dev(&warrior->dev); - warrior->dev.name = warrior_name; - warrior->dev.phys = warrior->phys; - warrior->dev.id.bustype = BUS_RS232; - warrior->dev.id.vendor = SERIO_WARRIOR; - warrior->dev.id.product = 0x0001; - warrior->dev.id.version = 0x0100; - warrior->dev.dev = &serio->dev; - - for (i = 0; i < 2; i++) { - warrior->dev.absmax[ABS_X+i] = -64; - warrior->dev.absmin[ABS_X+i] = 64; - warrior->dev.absflat[ABS_X+i] = 8; - } - - warrior->dev.absmax[ABS_THROTTLE] = -112; - warrior->dev.absmin[ABS_THROTTLE] = 112; - - for (i = 0; i < 2; i++) { - warrior->dev.absmax[ABS_HAT0X+i] = -1; - warrior->dev.absmin[ABS_HAT0X+i] = 1; - } - - warrior->dev.private = warrior; - - serio->private = warrior; + struct input_dev *input_dev; + int err = -ENOMEM; + + warrior = kzalloc(sizeof(struct warrior), GFP_KERNEL); + input_dev = input_allocate_device(); + if (!warrior || !input_dev) + goto fail1; + + warrior->dev = input_dev; + snprintf(warrior->phys, sizeof(warrior->phys), "%s/input0", serio->phys); + + input_dev->name = "Logitech WingMan Warrior"; + input_dev->phys = warrior->phys; + input_dev->id.bustype = BUS_RS232; + input_dev->id.vendor = SERIO_WARRIOR; + input_dev->id.product = 0x0001; + input_dev->id.version = 0x0100; + input_dev->cdev.dev = &serio->dev; + input_dev->private = warrior; + + input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL) | BIT(EV_ABS); + input_dev->keybit[LONG(BTN_TRIGGER)] = BIT(BTN_TRIGGER) | BIT(BTN_THUMB) | BIT(BTN_TOP) | BIT(BTN_TOP2); + input_dev->relbit[0] = BIT(REL_DIAL); + input_set_abs_params(input_dev, ABS_X, -64, 64, 0, 8); + input_set_abs_params(input_dev, ABS_Y, -64, 64, 0, 8); + input_set_abs_params(input_dev, ABS_THROTTLE, -112, 112, 0, 0); + input_set_abs_params(input_dev, ABS_HAT0X, -1, 1, 0, 0); + input_set_abs_params(input_dev, ABS_HAT0Y, -1, 1, 0, 0); + + serio_set_drvdata(serio, warrior); + + err = serio_open(serio, drv); + if (err) + goto fail2; + + err = input_register_device(warrior->dev); + if (err) + goto fail3; - if (serio_open(serio, drv)) { - kfree(warrior); - return; - } - - input_register_device(&warrior->dev); + return 0; - printk(KERN_INFO "input: Logitech WingMan Warrior on %s\n", serio->phys); + fail3: serio_close(serio); + fail2: serio_set_drvdata(serio, NULL); + fail1: input_free_device(input_dev); + kfree(warrior); + return err; } /* - * The serio device structure. + * The serio driver structure. */ +static struct serio_device_id warrior_serio_ids[] = { + { + .type = SERIO_RS232, + .proto = SERIO_WARRIOR, + .id = SERIO_ANY, + .extra = SERIO_ANY, + }, + { 0 } +}; + +MODULE_DEVICE_TABLE(serio, warrior_serio_ids); + static struct serio_driver warrior_drv = { .driver = { .name = "warrior", }, .description = DRIVER_DESC, + .id_table = warrior_serio_ids, .interrupt = warrior_interrupt, .connect = warrior_connect, .disconnect = warrior_disconnect, @@ -216,13 +222,12 @@ static struct serio_driver warrior_drv = { * The functions for inserting/removing us as a module. */ -int __init warrior_init(void) +static int __init warrior_init(void) { - serio_register_driver(&warrior_drv); - return 0; + return serio_register_driver(&warrior_drv); } -void __exit warrior_exit(void) +static void __exit warrior_exit(void) { serio_unregister_driver(&warrior_drv); }