X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=drivers%2Finput%2Fjoystick%2Ftwidjoy.c;h=9cf17d6ced820ca2c891669674bea3813078404e;hb=refs%2Fheads%2Fvserver;hp=0379bc1665252a062300e6040cdf9b0fdf793b38;hpb=f7f1b0f1e2fbadeab12d24236000e778aa9b1ead;p=linux-2.6.git diff --git a/drivers/input/joystick/twidjoy.c b/drivers/input/joystick/twidjoy.c index 0379bc166..9cf17d6ce 100644 --- a/drivers/input/joystick/twidjoy.c +++ b/drivers/input/joystick/twidjoy.c @@ -69,8 +69,6 @@ MODULE_LICENSE("GPL"); #define TWIDJOY_MAX_LENGTH 5 -static char *twidjoy_name = "Handykey Twiddler"; - static struct twidjoy_button_spec { int bitshift; int bitmask; @@ -95,7 +93,7 @@ twidjoy_buttons[] = { */ struct twidjoy { - struct input_dev dev; + struct input_dev *dev; int idx; unsigned char data[TWIDJOY_MAX_LENGTH]; char phys[32]; @@ -106,39 +104,33 @@ struct twidjoy { * Twiddler. It updates the data accordingly. */ -static void twidjoy_process_packet(struct twidjoy *twidjoy, struct pt_regs *regs) +static void twidjoy_process_packet(struct twidjoy *twidjoy) { - if (twidjoy->idx == TWIDJOY_MAX_LENGTH) { - struct input_dev *dev = &twidjoy->dev; - unsigned char *data = twidjoy->data; - struct twidjoy_button_spec *bp; - int button_bits, abs_x, abs_y; - - button_bits = ((data[1] & 0x7f) << 7) | (data[0] & 0x7f); - - input_regs(dev, regs); + struct input_dev *dev = twidjoy->dev; + unsigned char *data = twidjoy->data; + struct twidjoy_button_spec *bp; + int button_bits, abs_x, abs_y; - for (bp = twidjoy_buttons; bp->bitmask; bp++) { - int value = (button_bits & (bp->bitmask << bp->bitshift)) >> bp->bitshift; - int i; + button_bits = ((data[1] & 0x7f) << 7) | (data[0] & 0x7f); - for (i = 0; i < bp->bitmask; i++) - input_report_key(dev, bp->buttons[i], i+1 == value); - } + for (bp = twidjoy_buttons; bp->bitmask; bp++) { + int value = (button_bits & (bp->bitmask << bp->bitshift)) >> bp->bitshift; + int i; - abs_x = ((data[4] & 0x07) << 5) | ((data[3] & 0x7C) >> 2); - if (data[4] & 0x08) abs_x -= 256; + for (i = 0; i < bp->bitmask; i++) + input_report_key(dev, bp->buttons[i], i+1 == value); + } - abs_y = ((data[3] & 0x01) << 7) | ((data[2] & 0x7F) >> 0); - if (data[3] & 0x02) abs_y -= 256; + abs_x = ((data[4] & 0x07) << 5) | ((data[3] & 0x7C) >> 2); + if (data[4] & 0x08) abs_x -= 256; - input_report_abs(dev, ABS_X, -abs_x); - input_report_abs(dev, ABS_Y, +abs_y); + abs_y = ((data[3] & 0x01) << 7) | ((data[2] & 0x7F) >> 0); + if (data[3] & 0x02) abs_y -= 256; - input_sync(dev); - } + input_report_abs(dev, ABS_X, -abs_x); + input_report_abs(dev, ABS_Y, +abs_y); - return; + input_sync(dev); } /* @@ -147,7 +139,7 @@ static void twidjoy_process_packet(struct twidjoy *twidjoy, struct pt_regs *regs * packet processing routine. */ -static irqreturn_t twidjoy_interrupt(struct serio *serio, unsigned char data, unsigned int flags, struct pt_regs *regs) +static irqreturn_t twidjoy_interrupt(struct serio *serio, unsigned char data, unsigned int flags) { struct twidjoy *twidjoy = serio_get_drvdata(serio); @@ -164,7 +156,7 @@ static irqreturn_t twidjoy_interrupt(struct serio *serio, unsigned char data, un twidjoy->data[twidjoy->idx++] = data; if (twidjoy->idx == TWIDJOY_MAX_LENGTH) { - twidjoy_process_packet(twidjoy, regs); + twidjoy_process_packet(twidjoy); twidjoy->idx = 0; } @@ -179,9 +171,9 @@ static void twidjoy_disconnect(struct serio *serio) { struct twidjoy *twidjoy = serio_get_drvdata(serio); - input_unregister_device(&twidjoy->dev); serio_close(serio); serio_set_drvdata(serio, NULL); + input_unregister_device(twidjoy->dev); kfree(twidjoy); } @@ -195,59 +187,53 @@ static int twidjoy_connect(struct serio *serio, struct serio_driver *drv) { struct twidjoy_button_spec *bp; struct twidjoy *twidjoy; + struct input_dev *input_dev; + int err = -ENOMEM; int i; - int err; - - if (!(twidjoy = kmalloc(sizeof(struct twidjoy), GFP_KERNEL))) - return -ENOMEM; - - memset(twidjoy, 0, sizeof(struct twidjoy)); - - sprintf(twidjoy->phys, "%s/input0", serio->phys); - - init_input_dev(&twidjoy->dev); - twidjoy->dev.name = twidjoy_name; - twidjoy->dev.phys = twidjoy->phys; - twidjoy->dev.id.bustype = BUS_RS232; - twidjoy->dev.id.vendor = SERIO_TWIDJOY; - twidjoy->dev.id.product = 0x0001; - twidjoy->dev.id.version = 0x0100; - twidjoy->dev.dev = &serio->dev; - twidjoy->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); - - for (bp = twidjoy_buttons; bp->bitmask; bp++) { + twidjoy = kzalloc(sizeof(struct twidjoy), GFP_KERNEL); + input_dev = input_allocate_device(); + if (!twidjoy || !input_dev) + goto fail1; + + twidjoy->dev = input_dev; + snprintf(twidjoy->phys, sizeof(twidjoy->phys), "%s/input0", serio->phys); + + input_dev->name = "Handykey Twiddler"; + input_dev->phys = twidjoy->phys; + input_dev->id.bustype = BUS_RS232; + input_dev->id.vendor = SERIO_TWIDJOY; + input_dev->id.product = 0x0001; + input_dev->id.version = 0x0100; + input_dev->cdev.dev = &serio->dev; + input_dev->private = twidjoy; + + input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); + input_dev->absbit[0] = BIT(ABS_X) | BIT(ABS_Y); + input_set_abs_params(input_dev, ABS_X, -50, 50, 4, 4); + input_set_abs_params(input_dev, ABS_Y, -50, 50, 4, 4); + + for (bp = twidjoy_buttons; bp->bitmask; bp++) for (i = 0; i < bp->bitmask; i++) - set_bit(bp->buttons[i], twidjoy->dev.keybit); - } - - twidjoy->dev.absbit[0] = BIT(ABS_X) | BIT(ABS_Y); - - for (i = 0; i < 2; i++) { - twidjoy->dev.absmax[ABS_X+i] = 50; - twidjoy->dev.absmin[ABS_X+i] = -50; - - /* TODO: arndt 20010708: Are these values appropriate? */ - twidjoy->dev.absfuzz[ABS_X+i] = 4; - twidjoy->dev.absflat[ABS_X+i] = 4; - } - - twidjoy->dev.private = twidjoy; + set_bit(bp->buttons[i], input_dev->keybit); serio_set_drvdata(serio, twidjoy); err = serio_open(serio, drv); - if (err) { - serio_set_drvdata(serio, NULL); - kfree(twidjoy); - return err; - } - - input_register_device(&twidjoy->dev); + if (err) + goto fail2; - printk(KERN_INFO "input: %s on %s\n", twidjoy_name, serio->phys); + err = input_register_device(twidjoy->dev); + if (err) + goto fail3; return 0; + + fail3: serio_close(serio); + fail2: serio_set_drvdata(serio, NULL); + fail1: input_free_device(input_dev); + kfree(twidjoy); + return err; } /* @@ -281,13 +267,12 @@ static struct serio_driver twidjoy_drv = { * The functions for inserting/removing us as a module. */ -int __init twidjoy_init(void) +static int __init twidjoy_init(void) { - serio_register_driver(&twidjoy_drv); - return 0; + return serio_register_driver(&twidjoy_drv); } -void __exit twidjoy_exit(void) +static void __exit twidjoy_exit(void) { serio_unregister_driver(&twidjoy_drv); }