Commit 17dd3f0f authored by Dmitry Torokhov's avatar Dmitry Torokhov Committed by Greg Kroah-Hartman

[PATCH] drivers/input/joystick: convert to dynamic input_dev allocation

Input: convert drivers/input/joystick to dynamic input_dev allocation

This is required for input_dev sysfs integration
Signed-off-by: default avatarDmitry Torokhov <dtor@mail.ru>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 0259567a
...@@ -54,7 +54,7 @@ MODULE_LICENSE("GPL"); ...@@ -54,7 +54,7 @@ MODULE_LICENSE("GPL");
#define ADI_MIN_LENGTH 8 #define ADI_MIN_LENGTH 8
#define ADI_MIN_LEN_LENGTH 10 #define ADI_MIN_LEN_LENGTH 10
#define ADI_MIN_ID_LENGTH 66 #define ADI_MIN_ID_LENGTH 66
#define ADI_MAX_NAME_LENGTH 48 #define ADI_MAX_NAME_LENGTH 64
#define ADI_MAX_CNAME_LENGTH 16 #define ADI_MAX_CNAME_LENGTH 16
#define ADI_MAX_PHYS_LENGTH 64 #define ADI_MAX_PHYS_LENGTH 64
...@@ -106,7 +106,7 @@ static struct { ...@@ -106,7 +106,7 @@ static struct {
*/ */
struct adi { struct adi {
struct input_dev dev; struct input_dev *dev;
int length; int length;
int ret; int ret;
int idx; int idx;
...@@ -215,7 +215,7 @@ static inline int adi_get_bits(struct adi *adi, int count) ...@@ -215,7 +215,7 @@ static inline int adi_get_bits(struct adi *adi, int count)
static int adi_decode(struct adi *adi) static int adi_decode(struct adi *adi)
{ {
struct input_dev *dev = &adi->dev; struct input_dev *dev = adi->dev;
char *abs = adi->abs; char *abs = adi->abs;
short *key = adi->key; short *key = adi->key;
int i, t; int i, t;
...@@ -318,7 +318,8 @@ static void adi_init_digital(struct gameport *gameport) ...@@ -318,7 +318,8 @@ static void adi_init_digital(struct gameport *gameport)
for (i = 0; seq[i]; i++) { for (i = 0; seq[i]; i++) {
gameport_trigger(gameport); gameport_trigger(gameport);
if (seq[i] > 0) msleep(seq[i]); if (seq[i] > 0)
msleep(seq[i]);
if (seq[i] < 0) { if (seq[i] < 0) {
mdelay(-seq[i]); mdelay(-seq[i]);
udelay(-seq[i]*14); /* It looks like mdelay() is off by approx 1.4% */ udelay(-seq[i]*14); /* It looks like mdelay() is off by approx 1.4% */
...@@ -397,42 +398,46 @@ static void adi_id_decode(struct adi *adi, struct adi_port *port) ...@@ -397,42 +398,46 @@ static void adi_id_decode(struct adi *adi, struct adi_port *port)
} }
} }
static void adi_init_input(struct adi *adi, struct adi_port *port, int half) static int adi_init_input(struct adi *adi, struct adi_port *port, int half)
{ {
int i, t; struct input_dev *input_dev;
char buf[ADI_MAX_NAME_LENGTH]; char buf[ADI_MAX_NAME_LENGTH];
int i, t;
if (!adi->length) return; adi->dev = input_dev = input_allocate_device();
if (!input_dev)
init_input_dev(&adi->dev); return -ENOMEM;
t = adi->id < ADI_ID_MAX ? adi->id : ADI_ID_MAX; t = adi->id < ADI_ID_MAX ? adi->id : ADI_ID_MAX;
snprintf(buf, ADI_MAX_PHYS_LENGTH, adi_names[t], adi->id); snprintf(buf, ADI_MAX_PHYS_LENGTH, adi_names[t], adi->id);
snprintf(adi->name, ADI_MAX_NAME_LENGTH, "Logitech %s", buf); snprintf(adi->name, ADI_MAX_NAME_LENGTH, "Logitech %s [%s]", buf, adi->cname);
snprintf(adi->phys, ADI_MAX_PHYS_LENGTH, "%s/input%d", port->gameport->phys, half); snprintf(adi->phys, ADI_MAX_PHYS_LENGTH, "%s/input%d", port->gameport->phys, half);
adi->abs = adi_abs[t]; adi->abs = adi_abs[t];
adi->key = adi_key[t]; adi->key = adi_key[t];
adi->dev.open = adi_open; input_dev->name = adi->name;
adi->dev.close = adi_close; input_dev->phys = adi->phys;
input_dev->id.bustype = BUS_GAMEPORT;
input_dev->id.vendor = GAMEPORT_ID_VENDOR_LOGITECH;
input_dev->id.product = adi->id;
input_dev->id.version = 0x0100;
input_dev->cdev.dev = &port->gameport->dev;
input_dev->private = port;
adi->dev.name = adi->name; input_dev->open = adi_open;
adi->dev.phys = adi->phys; input_dev->close = adi_close;
adi->dev.id.bustype = BUS_GAMEPORT;
adi->dev.id.vendor = GAMEPORT_ID_VENDOR_LOGITECH;
adi->dev.id.product = adi->id;
adi->dev.id.version = 0x0100;
adi->dev.private = port; input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
adi->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
for (i = 0; i < adi->axes10 + adi->axes8 + (adi->hats + (adi->pad != -1)) * 2; i++) for (i = 0; i < adi->axes10 + adi->axes8 + (adi->hats + (adi->pad != -1)) * 2; i++)
set_bit(adi->abs[i], adi->dev.absbit); set_bit(adi->abs[i], input_dev->absbit);
for (i = 0; i < adi->buttons; i++) for (i = 0; i < adi->buttons; i++)
set_bit(adi->key[i], adi->dev.keybit); set_bit(adi->key[i], input_dev->keybit);
return 0;
} }
static void adi_init_center(struct adi *adi) static void adi_init_center(struct adi *adi)
...@@ -445,17 +450,17 @@ static void adi_init_center(struct adi *adi) ...@@ -445,17 +450,17 @@ static void adi_init_center(struct adi *adi)
for (i = 0; i < adi->axes10 + adi->axes8 + (adi->hats + (adi->pad != -1)) * 2; i++) { for (i = 0; i < adi->axes10 + adi->axes8 + (adi->hats + (adi->pad != -1)) * 2; i++) {
t = adi->abs[i]; t = adi->abs[i];
x = adi->dev.abs[t]; x = adi->dev->abs[t];
if (t == ABS_THROTTLE || t == ABS_RUDDER || adi->id == ADI_ID_WGPE) if (t == ABS_THROTTLE || t == ABS_RUDDER || adi->id == ADI_ID_WGPE)
x = i < adi->axes10 ? 512 : 128; x = i < adi->axes10 ? 512 : 128;
if (i < adi->axes10) if (i < adi->axes10)
input_set_abs_params(&adi->dev, t, 64, x * 2 - 64, 2, 16); input_set_abs_params(adi->dev, t, 64, x * 2 - 64, 2, 16);
else if (i < adi->axes10 + adi->axes8) else if (i < adi->axes10 + adi->axes8)
input_set_abs_params(&adi->dev, t, 48, x * 2 - 48, 1, 16); input_set_abs_params(adi->dev, t, 48, x * 2 - 48, 1, 16);
else else
input_set_abs_params(&adi->dev, t, -1, 1, 0, 0); input_set_abs_params(adi->dev, t, -1, 1, 0, 0);
} }
} }
...@@ -469,7 +474,8 @@ static int adi_connect(struct gameport *gameport, struct gameport_driver *drv) ...@@ -469,7 +474,8 @@ static int adi_connect(struct gameport *gameport, struct gameport_driver *drv)
int i; int i;
int err; int err;
if (!(port = kzalloc(sizeof(struct adi_port), GFP_KERNEL))) port = kzalloc(sizeof(struct adi_port), GFP_KERNEL);
if (!port)
return -ENOMEM; return -ENOMEM;
port->gameport = gameport; port->gameport = gameport;
...@@ -477,10 +483,8 @@ static int adi_connect(struct gameport *gameport, struct gameport_driver *drv) ...@@ -477,10 +483,8 @@ static int adi_connect(struct gameport *gameport, struct gameport_driver *drv)
gameport_set_drvdata(gameport, port); gameport_set_drvdata(gameport, port);
err = gameport_open(gameport, drv, GAMEPORT_MODE_RAW); err = gameport_open(gameport, drv, GAMEPORT_MODE_RAW);
if (err) { if (err)
kfree(port); goto fail1;
return err;
}
adi_init_digital(gameport); adi_init_digital(gameport);
adi_read_packet(port); adi_read_packet(port);
...@@ -490,13 +494,18 @@ static int adi_connect(struct gameport *gameport, struct gameport_driver *drv) ...@@ -490,13 +494,18 @@ static int adi_connect(struct gameport *gameport, struct gameport_driver *drv)
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
adi_id_decode(port->adi + i, port); adi_id_decode(port->adi + i, port);
adi_init_input(port->adi + i, port, i);
if (!port->adi[i].length)
continue;
err = adi_init_input(port->adi + i, port, i);
if (err)
goto fail2;
} }
if (!port->adi[0].length && !port->adi[1].length) { if (!port->adi[0].length && !port->adi[1].length) {
gameport_close(gameport); err = -ENODEV;
kfree(port); goto fail2;
return -ENODEV;
} }
gameport_set_poll_handler(gameport, adi_poll); gameport_set_poll_handler(gameport, adi_poll);
...@@ -511,12 +520,18 @@ static int adi_connect(struct gameport *gameport, struct gameport_driver *drv) ...@@ -511,12 +520,18 @@ static int adi_connect(struct gameport *gameport, struct gameport_driver *drv)
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
if (port->adi[i].length > 0) { if (port->adi[i].length > 0) {
adi_init_center(port->adi + i); adi_init_center(port->adi + i);
input_register_device(&port->adi[i].dev); input_register_device(port->adi[i].dev);
printk(KERN_INFO "input: %s [%s] on %s\n",
port->adi[i].name, port->adi[i].cname, gameport->phys);
} }
return 0; return 0;
fail2: for (i = 0; i < 2; i++)
if (port->adi[i].dev)
input_free_device(port->adi[i].dev);
gameport_close(gameport);
fail1: gameport_set_drvdata(gameport, NULL);
kfree(port);
return err;
} }
static void adi_disconnect(struct gameport *gameport) static void adi_disconnect(struct gameport *gameport)
...@@ -526,7 +541,7 @@ static void adi_disconnect(struct gameport *gameport) ...@@ -526,7 +541,7 @@ static void adi_disconnect(struct gameport *gameport)
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
if (port->adi[i].length > 0) if (port->adi[i].length > 0)
input_unregister_device(&port->adi[i].dev); input_unregister_device(port->adi[i].dev);
gameport_close(gameport); gameport_close(gameport);
gameport_set_drvdata(gameport, NULL); gameport_set_drvdata(gameport, NULL);
kfree(port); kfree(port);
......
...@@ -53,11 +53,9 @@ __obsolete_setup("amijoy="); ...@@ -53,11 +53,9 @@ __obsolete_setup("amijoy=");
static int amijoy_used; static int amijoy_used;
static DECLARE_MUTEX(amijoy_sem); static DECLARE_MUTEX(amijoy_sem);
static struct input_dev amijoy_dev[2]; static struct input_dev *amijoy_dev[2];
static char *amijoy_phys[2] = { "amijoy/input0", "amijoy/input1" }; static char *amijoy_phys[2] = { "amijoy/input0", "amijoy/input1" };
static char *amijoy_name = "Amiga joystick";
static irqreturn_t amijoy_interrupt(int irq, void *dummy, struct pt_regs *fp) static irqreturn_t amijoy_interrupt(int irq, void *dummy, struct pt_regs *fp)
{ {
int i, data = 0, button = 0; int i, data = 0, button = 0;
...@@ -70,15 +68,15 @@ static irqreturn_t amijoy_interrupt(int irq, void *dummy, struct pt_regs *fp) ...@@ -70,15 +68,15 @@ static irqreturn_t amijoy_interrupt(int irq, void *dummy, struct pt_regs *fp)
case 1: data = ~custom.joy1dat; button = (~ciaa.pra >> 7) & 1; break; case 1: data = ~custom.joy1dat; button = (~ciaa.pra >> 7) & 1; break;
} }
input_regs(amijoy_dev + i, fp); input_regs(amijoy_dev[i], fp);
input_report_key(amijoy_dev + i, BTN_TRIGGER, button); input_report_key(amijoy_dev[i], BTN_TRIGGER, button);
input_report_abs(amijoy_dev + i, ABS_X, ((data >> 1) & 1) - ((data >> 9) & 1)); input_report_abs(amijoy_dev[i], ABS_X, ((data >> 1) & 1) - ((data >> 9) & 1));
data = ~(data ^ (data << 1)); data = ~(data ^ (data << 1));
input_report_abs(amijoy_dev + i, ABS_Y, ((data >> 1) & 1) - ((data >> 9) & 1)); input_report_abs(amijoy_dev[i], ABS_Y, ((data >> 1) & 1) - ((data >> 9) & 1));
input_sync(amijoy_dev + i); input_sync(amijoy_dev[i]);
} }
return IRQ_HANDLED; return IRQ_HANDLED;
} }
...@@ -114,39 +112,52 @@ static void amijoy_close(struct input_dev *dev) ...@@ -114,39 +112,52 @@ static void amijoy_close(struct input_dev *dev)
static int __init amijoy_init(void) static int __init amijoy_init(void)
{ {
int i, j; int i, j;
int err;
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++) {
if (amijoy[i]) { if (!amijoy[i])
if (!request_mem_region(CUSTOM_PHYSADDR+10+i*2, 2, continue;
"amijoy [Denise]")) {
if (i == 1 && amijoy[0]) { amijoy_dev[i] = input_allocate_device();
input_unregister_device(amijoy_dev); if (!amijoy_dev[i]) {
release_mem_region(CUSTOM_PHYSADDR+10, 2); err = -ENOMEM;
goto fail;
} }
return -EBUSY;
if (!request_mem_region(CUSTOM_PHYSADDR + 10 + i * 2, 2, "amijoy [Denise]")) {
input_free_device(amijoy_dev[i]);
err = -EBUSY;
goto fail;
} }
amijoy_dev[i].open = amijoy_open; amijoy_dev[i]->name = "Amiga joystick";
amijoy_dev[i].close = amijoy_close; amijoy_dev[i]->phys = amijoy_phys[i];
amijoy_dev[i].evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); amijoy_dev[i]->id.bustype = BUS_AMIGA;
amijoy_dev[i].absbit[0] = BIT(ABS_X) | BIT(ABS_Y); amijoy_dev[i]->id.vendor = 0x0001;
amijoy_dev[i].keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT); amijoy_dev[i]->id.product = 0x0003;
amijoy_dev[i]->id.version = 0x0100;
amijoy_dev[i]->open = amijoy_open;
amijoy_dev[i]->close = amijoy_close;
amijoy_dev[i]->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
amijoy_dev[i]->absbit[0] = BIT(ABS_X) | BIT(ABS_Y);
amijoy_dev[i]->keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
for (j = 0; j < 2; j++) { for (j = 0; j < 2; j++) {
amijoy_dev[i].absmin[ABS_X + j] = -1; amijoy_dev[i]->absmin[ABS_X + j] = -1;
amijoy_dev[i].absmax[ABS_X + j] = 1; amijoy_dev[i]->absmax[ABS_X + j] = 1;
} }
amijoy_dev[i].name = amijoy_name; input_register_device(amijoy_dev[i]);
amijoy_dev[i].phys = amijoy_phys[i];
amijoy_dev[i].id.bustype = BUS_AMIGA;
amijoy_dev[i].id.vendor = 0x0001;
amijoy_dev[i].id.product = 0x0003;
amijoy_dev[i].id.version = 0x0100;
input_register_device(amijoy_dev + i);
printk(KERN_INFO "input: %s at joy%ddat\n", amijoy_name, i);
} }
return 0; return 0;
fail: while (--i >= 0)
if (amijoy[i]) {
input_unregister_device(amijoy_dev[i]);
release_mem_region(CUSTOM_PHYSADDR + 10 + i * 2, 2);
}
return err;
} }
static void __exit amijoy_exit(void) static void __exit amijoy_exit(void)
...@@ -155,8 +166,8 @@ static void __exit amijoy_exit(void) ...@@ -155,8 +166,8 @@ static void __exit amijoy_exit(void)
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
if (amijoy[i]) { if (amijoy[i]) {
input_unregister_device(amijoy_dev + i); input_unregister_device(amijoy_dev[i]);
release_mem_region(CUSTOM_PHYSADDR+10+i*2, 2); release_mem_region(CUSTOM_PHYSADDR + 10 + i * 2, 2);
} }
} }
......
...@@ -111,7 +111,7 @@ static short analog_joy_btn[] = { BTN_TRIGGER, BTN_THUMB, BTN_TOP, BTN_TOP2, BTN ...@@ -111,7 +111,7 @@ static short analog_joy_btn[] = { BTN_TRIGGER, BTN_THUMB, BTN_TOP, BTN_TOP2, BTN
static unsigned char analog_chf[] = { 0xf, 0x0, 0x1, 0x9, 0x2, 0x4, 0xc, 0x8, 0x3, 0x5, 0xb, 0x7, 0xd, 0xe, 0xa, 0x6 }; static unsigned char analog_chf[] = { 0xf, 0x0, 0x1, 0x9, 0x2, 0x4, 0xc, 0x8, 0x3, 0x5, 0xb, 0x7, 0xd, 0xe, 0xa, 0x6 };
struct analog { struct analog {
struct input_dev dev; struct input_dev *dev;
int mask; int mask;
short *buttons; short *buttons;
char name[ANALOG_MAX_NAME_LENGTH]; char name[ANALOG_MAX_NAME_LENGTH];
...@@ -182,7 +182,7 @@ static unsigned long analog_faketime = 0; ...@@ -182,7 +182,7 @@ static unsigned long analog_faketime = 0;
static void analog_decode(struct analog *analog, int *axes, int *initial, int buttons) static void analog_decode(struct analog *analog, int *axes, int *initial, int buttons)
{ {
struct input_dev *dev = &analog->dev; struct input_dev *dev = analog->dev;
int i, j; int i, j;
if (analog->mask & ANALOG_HAT_FCS) if (analog->mask & ANALOG_HAT_FCS)
...@@ -428,27 +428,30 @@ static void analog_name(struct analog *analog) ...@@ -428,27 +428,30 @@ static void analog_name(struct analog *analog)
* analog_init_device() * analog_init_device()
*/ */
static void analog_init_device(struct analog_port *port, struct analog *analog, int index) static int analog_init_device(struct analog_port *port, struct analog *analog, int index)
{ {
struct input_dev *input_dev;
int i, j, t, v, w, x, y, z; int i, j, t, v, w, x, y, z;
analog_name(analog); analog_name(analog);
sprintf(analog->phys, "%s/input%d", port->gameport->phys, index); sprintf(analog->phys, "%s/input%d", port->gameport->phys, index);
analog->buttons = (analog->mask & ANALOG_GAMEPAD) ? analog_pad_btn : analog_joy_btn; analog->buttons = (analog->mask & ANALOG_GAMEPAD) ? analog_pad_btn : analog_joy_btn;
init_input_dev(&analog->dev); analog->dev = input_dev = input_allocate_device();
if (!input_dev)
return -ENOMEM;
analog->dev.name = analog->name; input_dev->name = analog->name;
analog->dev.phys = analog->phys; input_dev->phys = analog->phys;
analog->dev.id.bustype = BUS_GAMEPORT; input_dev->id.bustype = BUS_GAMEPORT;
analog->dev.id.vendor = GAMEPORT_ID_VENDOR_ANALOG; input_dev->id.vendor = GAMEPORT_ID_VENDOR_ANALOG;
analog->dev.id.product = analog->mask >> 4; input_dev->id.product = analog->mask >> 4;
analog->dev.id.version = 0x0100; input_dev->id.version = 0x0100;
analog->dev.open = analog_open; input_dev->open = analog_open;
analog->dev.close = analog_close; input_dev->close = analog_close;
analog->dev.private = port; input_dev->private = port;
analog->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
for (i = j = 0; i < 4; i++) for (i = j = 0; i < 4; i++)
if (analog->mask & (1 << i)) { if (analog->mask & (1 << i)) {
...@@ -461,8 +464,6 @@ static void analog_init_device(struct analog_port *port, struct analog *analog, ...@@ -461,8 +464,6 @@ static void analog_init_device(struct analog_port *port, struct analog *analog,
v = (x >> 3); v = (x >> 3);
w = (x >> 3); w = (x >> 3);
set_bit(t, analog->dev.absbit);
if ((i == 2 || i == 3) && (j == 2 || j == 3) && (z > (y >> 3))) if ((i == 2 || i == 3) && (j == 2 || j == 3) && (z > (y >> 3)))
x = y; x = y;
...@@ -472,11 +473,7 @@ static void analog_init_device(struct analog_port *port, struct analog *analog, ...@@ -472,11 +473,7 @@ static void analog_init_device(struct analog_port *port, struct analog *analog,
w = (x >> 4); w = (x >> 4);
} }
analog->dev.absmax[t] = (x << 1) - v; input_set_abs_params(input_dev, t, v, (x << 1) - v, port->fuzz, w);
analog->dev.absmin[t] = v;
analog->dev.absfuzz[t] = port->fuzz;
analog->dev.absflat[t] = w;
j++; j++;
} }
...@@ -484,41 +481,30 @@ static void analog_init_device(struct analog_port *port, struct analog *analog, ...@@ -484,41 +481,30 @@ static void analog_init_device(struct analog_port *port, struct analog *analog,
if (analog->mask & analog_exts[i]) if (analog->mask & analog_exts[i])
for (x = 0; x < 2; x++) { for (x = 0; x < 2; x++) {
t = analog_hats[j++]; t = analog_hats[j++];
set_bit(t, analog->dev.absbit); input_set_abs_params(input_dev, t, -1, 1, 0, 0);
analog->dev.absmax[t] = 1;
analog->dev.absmin[t] = -1;
} }
for (i = j = 0; i < 4; i++) for (i = j = 0; i < 4; i++)
if (analog->mask & (0x10 << i)) if (analog->mask & (0x10 << i))
set_bit(analog->buttons[j++], analog->dev.keybit); set_bit(analog->buttons[j++], input_dev->keybit);
if (analog->mask & ANALOG_BTNS_CHF) if (analog->mask & ANALOG_BTNS_CHF)
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
set_bit(analog->buttons[j++], analog->dev.keybit); set_bit(analog->buttons[j++], input_dev->keybit);
if (analog->mask & ANALOG_HBTN_CHF) if (analog->mask & ANALOG_HBTN_CHF)
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
set_bit(analog->buttons[j++], analog->dev.keybit); set_bit(analog->buttons[j++], input_dev->keybit);
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
if (analog->mask & (ANALOG_BTN_TL << i)) if (analog->mask & (ANALOG_BTN_TL << i))
set_bit(analog_pads[i], analog->dev.keybit); set_bit(analog_pads[i], input_dev->keybit);
analog_decode(analog, port->axes, port->initial, port->buttons); analog_decode(analog, port->axes, port->initial, port->buttons);
input_register_device(&analog->dev); input_register_device(analog->dev);
printk(KERN_INFO "input: %s at %s", analog->name, port->gameport->phys);
if (port->cooked) return 0;
printk(" [ADC port]\n");
else
printk(" [%s timer, %d %sHz clock, %d ns res]\n", TIME_NAME,
port->speed > 10000 ? (port->speed + 800) / 1000 : port->speed,
port->speed > 10000 ? "M" : "k",
port->speed > 10000 ? (port->loop * 1000) / (port->speed / 1000)
: (port->loop * 1000000) / port->speed);
} }
/* /*
...@@ -659,37 +645,41 @@ static int analog_connect(struct gameport *gameport, struct gameport_driver *drv ...@@ -659,37 +645,41 @@ static int analog_connect(struct gameport *gameport, struct gameport_driver *drv
return - ENOMEM; return - ENOMEM;
err = analog_init_port(gameport, drv, port); err = analog_init_port(gameport, drv, port);
if (err) { if (err)
kfree(port); goto fail1;
return err;
}
err = analog_init_masks(port); err = analog_init_masks(port);
if (err) { if (err)
gameport_close(gameport); goto fail2;
gameport_set_drvdata(gameport, NULL);
kfree(port);
return err;
}
gameport_set_poll_handler(gameport, analog_poll); gameport_set_poll_handler(gameport, analog_poll);
gameport_set_poll_interval(gameport, 10); gameport_set_poll_interval(gameport, 10);
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
if (port->analog[i].mask) if (port->analog[i].mask) {
analog_init_device(port, port->analog + i, i); err = analog_init_device(port, port->analog + i, i);
if (err)
goto fail3;
}
return 0; return 0;
fail3: while (--i >= 0)
input_unregister_device(port->analog[i].dev);
fail2: gameport_close(gameport);
fail1: gameport_set_drvdata(gameport, NULL);
kfree(port);
return err;
} }
static void analog_disconnect(struct gameport *gameport) static void analog_disconnect(struct gameport *gameport)
{ {
int i;
struct analog_port *port = gameport_get_drvdata(gameport); struct analog_port *port = gameport_get_drvdata(gameport);
int i;
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
if (port->analog[i].mask) if (port->analog[i].mask)
input_unregister_device(&port->analog[i].dev); input_unregister_device(port->analog[i].dev);
gameport_close(gameport); gameport_close(gameport);
gameport_set_drvdata(gameport, NULL); gameport_set_drvdata(gameport, NULL);
printk(KERN_INFO "analog.c: %d out of %d reads (%d%%) on %s failed\n", printk(KERN_INFO "analog.c: %d out of %d reads (%d%%) on %s failed\n",
......
...@@ -44,13 +44,11 @@ MODULE_LICENSE("GPL"); ...@@ -44,13 +44,11 @@ MODULE_LICENSE("GPL");
#define COBRA_MAX_STROBE 45 /* 45 us max wait for first strobe */ #define COBRA_MAX_STROBE 45 /* 45 us max wait for first strobe */
#define COBRA_LENGTH 36 #define COBRA_LENGTH 36
static char* cobra_name = "Creative Labs Blaster GamePad Cobra";
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 }; 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 };
struct cobra { struct cobra {
struct gameport *gameport; struct gameport *gameport;
struct input_dev dev[2]; struct input_dev *dev[2];
int reads; int reads;
int bads; int bads;
unsigned char exists; unsigned char exists;
...@@ -128,7 +126,7 @@ static void cobra_poll(struct gameport *gameport) ...@@ -128,7 +126,7 @@ static void cobra_poll(struct gameport *gameport)
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
if (cobra->exists & r & (1 << i)) { if (cobra->exists & r & (1 << i)) {
dev = cobra->dev + i; dev = cobra->dev[i];
input_report_abs(dev, ABS_X, ((data[i] >> 4) & 1) - ((data[i] >> 3) & 1)); input_report_abs(dev, ABS_X, ((data[i] >> 4) & 1) - ((data[i] >> 3) & 1));
input_report_abs(dev, ABS_Y, ((data[i] >> 2) & 1) - ((data[i] >> 1) & 1)); input_report_abs(dev, ABS_Y, ((data[i] >> 2) & 1) - ((data[i] >> 1) & 1));
...@@ -159,11 +157,13 @@ static void cobra_close(struct input_dev *dev) ...@@ -159,11 +157,13 @@ static void cobra_close(struct input_dev *dev)
static int cobra_connect(struct gameport *gameport, struct gameport_driver *drv) static int cobra_connect(struct gameport *gameport, struct gameport_driver *drv)
{ {
struct cobra *cobra; struct cobra *cobra;
struct input_dev *input_dev;
unsigned int data[2]; unsigned int data[2];
int i, j; int i, j;
int err; int err;
if (!(cobra = kzalloc(sizeof(struct cobra), GFP_KERNEL))) cobra = kzalloc(sizeof(struct cobra), GFP_KERNEL);
if (!cobra)
return -ENOMEM; return -ENOMEM;
cobra->gameport = gameport; cobra->gameport = gameport;
...@@ -191,38 +191,46 @@ static int cobra_connect(struct gameport *gameport, struct gameport_driver *drv) ...@@ -191,38 +191,46 @@ static int cobra_connect(struct gameport *gameport, struct gameport_driver *drv)
gameport_set_poll_handler(gameport, cobra_poll); gameport_set_poll_handler(gameport, cobra_poll);
gameport_set_poll_interval(gameport, 20); gameport_set_poll_interval(gameport, 20);
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++) {
if ((cobra->exists >> i) & 1) { if (~(cobra->exists >> i) & 1)
continue;
sprintf(cobra->phys[i], "%s/input%d", gameport->phys, i);
cobra->dev[i].private = cobra;
cobra->dev[i].open = cobra_open;
cobra->dev[i].close = cobra_close;
cobra->dev[i].name = cobra_name;
cobra->dev[i].phys = cobra->phys[i];
cobra->dev[i].id.bustype = BUS_GAMEPORT;
cobra->dev[i].id.vendor = GAMEPORT_ID_VENDOR_CREATIVE;
cobra->dev[i].id.product = 0x0008;
cobra->dev[i].id.version = 0x0100;
cobra->dev[i].evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); cobra->dev[i] = input_dev = input_allocate_device();
if (!input_dev) {
err = -ENOMEM;
goto fail3;
}
input_set_abs_params(&cobra->dev[i], ABS_X, -1, 1, 0, 0); sprintf(cobra->phys[i], "%s/input%d", gameport->phys, i);
input_set_abs_params(&cobra->dev[i], ABS_Y, -1, 1, 0, 0);
input_dev->name = "Creative Labs Blaster GamePad Cobra";
input_dev->phys = cobra->phys[i];
input_dev->id.bustype = BUS_GAMEPORT;
input_dev->id.vendor = GAMEPORT_ID_VENDOR_CREATIVE;
input_dev->id.product = 0x0008;
input_dev->id.version = 0x0100;
input_dev->cdev.dev = &gameport->dev;
input_dev->private = cobra;
input_dev->open = cobra_open;
input_dev->close = cobra_close;
input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
input_set_abs_params(input_dev, ABS_X, -1, 1, 0, 0);
input_set_abs_params(input_dev, ABS_Y, -1, 1, 0, 0);
for (j = 0; cobra_btn[j]; j++) for (j = 0; cobra_btn[j]; j++)
set_bit(cobra_btn[j], cobra->dev[i].keybit); set_bit(cobra_btn[j], input_dev->keybit);
input_register_device(&cobra->dev[i]); input_register_device(cobra->dev[i]);
printk(KERN_INFO "input: %s on %s\n", cobra_name, gameport->phys);
} }
return 0; return 0;
fail2: gameport_close(gameport); fail3: for (i = 0; i < 2; i++)
fail1: gameport_set_drvdata(gameport, NULL); if (cobra->dev[i])
input_unregister_device(cobra->dev[i]);
fail2: gameport_close(gameport);
fail1: gameport_set_drvdata(gameport, NULL);
kfree(cobra); kfree(cobra);
return err; return err;
} }
...@@ -234,7 +242,7 @@ static void cobra_disconnect(struct gameport *gameport) ...@@ -234,7 +242,7 @@ static void cobra_disconnect(struct gameport *gameport)
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
if ((cobra->exists >> i) & 1) if ((cobra->exists >> i) & 1)
input_unregister_device(cobra->dev + i); input_unregister_device(cobra->dev[i]);
gameport_close(gameport); gameport_close(gameport);
gameport_set_drvdata(gameport, NULL); gameport_set_drvdata(gameport, NULL);
kfree(cobra); kfree(cobra);
......
...@@ -43,25 +43,28 @@ MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); ...@@ -43,25 +43,28 @@ MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
MODULE_DESCRIPTION("Atari, Amstrad, Commodore, Amiga, Sega, etc. joystick driver"); MODULE_DESCRIPTION("Atari, Amstrad, Commodore, Amiga, Sega, etc. joystick driver");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
static int db9[] __initdata = { -1, 0 }; struct db9_config {
static int db9_nargs __initdata = 0; int args[2];
module_param_array_named(dev, db9, int, &db9_nargs, 0); int nargs;
MODULE_PARM_DESC(dev, "Describes first attached device (<parport#>,<type>)"); };
static int db9_2[] __initdata = { -1, 0 }; #define DB9_MAX_PORTS 3
static int db9_nargs_2 __initdata = 0; static struct db9_config db9[DB9_MAX_PORTS] __initdata;
module_param_array_named(dev2, db9_2, int, &db9_nargs_2, 0);
MODULE_PARM_DESC(dev2, "Describes second attached device (<parport#>,<type>)");
static int db9_3[] __initdata = { -1, 0 }; module_param_array_named(dev, db9[0].args, int, &db9[0].nargs, 0);
static int db9_nargs_3 __initdata = 0; MODULE_PARM_DESC(dev, "Describes first attached device (<parport#>,<type>)");
module_param_array_named(dev3, db9_3, int, &db9_nargs_3, 0); module_param_array_named(dev2, db9[1].args, int, &db9[0].nargs, 0);
MODULE_PARM_DESC(dev2, "Describes second attached device (<parport#>,<type>)");
module_param_array_named(dev3, db9[2].args, int, &db9[2].nargs, 0);
MODULE_PARM_DESC(dev3, "Describes third attached device (<parport#>,<type>)"); MODULE_PARM_DESC(dev3, "Describes third attached device (<parport#>,<type>)");
__obsolete_setup("db9="); __obsolete_setup("db9=");
__obsolete_setup("db9_2="); __obsolete_setup("db9_2=");
__obsolete_setup("db9_3="); __obsolete_setup("db9_3=");
#define DB9_ARG_PARPORT 0
#define DB9_ARG_MODE 1
#define DB9_MULTI_STICK 0x01 #define DB9_MULTI_STICK 0x01
#define DB9_MULTI2_STICK 0x02 #define DB9_MULTI2_STICK 0x02
#define DB9_GENESIS_PAD 0x03 #define DB9_GENESIS_PAD 0x03
...@@ -87,40 +90,53 @@ __obsolete_setup("db9_3="); ...@@ -87,40 +90,53 @@ __obsolete_setup("db9_3=");
#define DB9_NORMAL 0x0a #define DB9_NORMAL 0x0a
#define DB9_NOSELECT 0x08 #define DB9_NOSELECT 0x08
#define DB9_MAX_DEVICES 2
#define DB9_GENESIS6_DELAY 14 #define DB9_GENESIS6_DELAY 14
#define DB9_REFRESH_TIME HZ/100 #define DB9_REFRESH_TIME HZ/100
#define DB9_MAX_DEVICES 2
struct db9_mode_data {
const char *name;
const short *buttons;
int n_buttons;
int n_pads;
int n_axis;
int bidirectional;
int reverse;
};
struct db9 { struct db9 {
struct input_dev dev[DB9_MAX_DEVICES]; struct input_dev *dev[DB9_MAX_DEVICES];
struct timer_list timer; struct timer_list timer;
struct pardevice *pd; struct pardevice *pd;
int mode; int mode;
int used; int used;
struct semaphore sem; struct semaphore sem;
char phys[2][32]; char phys[DB9_MAX_DEVICES][32];
}; };
static struct db9 *db9_base[3]; static struct db9 *db9_base[3];
static short db9_multi_btn[] = { BTN_TRIGGER, BTN_THUMB }; static const short db9_multi_btn[] = { BTN_TRIGGER, BTN_THUMB };
static short db9_genesis_btn[] = { BTN_START, BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_MODE }; static const short db9_genesis_btn[] = { BTN_START, BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_MODE };
static short db9_cd32_btn[] = { BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_TL, BTN_TR, BTN_START }; static const short db9_cd32_btn[] = { BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_TL, BTN_TR, BTN_START };
static char db9_buttons[DB9_MAX_PAD] = { 0, 1, 2, 4, 0, 6, 8, 9, 1, 1, 7, 9, 9 };
static short *db9_btn[DB9_MAX_PAD] = { NULL, db9_multi_btn, db9_multi_btn, db9_genesis_btn, NULL, db9_genesis_btn,
db9_genesis_btn, db9_cd32_btn, db9_multi_btn, db9_multi_btn, db9_cd32_btn,
db9_cd32_btn, db9_cd32_btn };
static char *db9_name[DB9_MAX_PAD] = { NULL, "Multisystem joystick", "Multisystem joystick (2 fire)", "Genesis pad",
NULL, "Genesis 5 pad", "Genesis 6 pad", "Saturn pad", "Multisystem (0.8.0.2) joystick",
"Multisystem (0.8.0.2-dual) joystick", "Amiga CD-32 pad", "Saturn dpp", "Saturn dpp dual" };
static const int db9_max_pads[DB9_MAX_PAD] = { 0, 1, 1, 1, 0, 1, 1, 6, 1, 2, 1, 6, 12 };
static const int db9_num_axis[DB9_MAX_PAD] = { 0, 2, 2, 2, 0, 2, 2, 7, 2, 2, 2 ,7, 7 };
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 }; 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 };
static const int db9_bidirectional[DB9_MAX_PAD] = { 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0 };
static const int db9_reverse[DB9_MAX_PAD] = { 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0 }; static const struct db9_mode_data db9_modes[] = {
{ NULL, NULL, 0, 0, 0, 0, 0 },
{ "Multisystem joystick", db9_multi_btn, 1, 1, 2, 1, 1 },
{ "Multisystem joystick (2 fire)", db9_multi_btn, 2, 1, 2, 1, 1 },
{ "Genesis pad", db9_genesis_btn, 4, 1, 2, 1, 1 },
{ NULL, NULL, 0, 0, 0, 0, 0 },
{ "Genesis 5 pad", db9_genesis_btn, 6, 1, 2, 1, 1 },
{ "Genesis 6 pad", db9_genesis_btn, 8, 1, 2, 1, 1 },
{ "Saturn pad", db9_cd32_btn, 9, 6, 7, 0, 1 },
{ "Multisystem (0.8.0.2) joystick", db9_multi_btn, 1, 1, 2, 1, 1 },
{ "Multisystem (0.8.0.2-dual) joystick", db9_multi_btn, 1, 2, 2, 1, 1 },
{ "Amiga CD-32 pad", db9_cd32_btn, 7, 1, 2, 1, 1 },
{ "Saturn dpp", db9_cd32_btn, 9, 6, 7, 0, 0 },
{ "Saturn dpp dual", db9_cd32_btn, 9, 12, 7, 0, 0 },
};
/* /*
* Saturn controllers * Saturn controllers
...@@ -342,7 +358,7 @@ static int db9_saturn(int mode, struct parport *port, struct input_dev *dev) ...@@ -342,7 +358,7 @@ static int db9_saturn(int mode, struct parport *port, struct input_dev *dev)
default: default:
return -1; return -1;
} }
max_pads = min(db9_max_pads[mode], DB9_MAX_DEVICES); max_pads = min(db9_modes[mode].n_pads, DB9_MAX_DEVICES);
for (tmp = 0, i = 0; i < n; i++) { for (tmp = 0, i = 0; i < n; i++) {
id = db9_saturn_read_packet(port, data, type + i, 1); id = db9_saturn_read_packet(port, data, type + i, 1);
tmp = db9_saturn_report(id, data, dev, tmp, max_pads); tmp = db9_saturn_report(id, data, dev, tmp, max_pads);
...@@ -354,17 +370,18 @@ static void db9_timer(unsigned long private) ...@@ -354,17 +370,18 @@ static void db9_timer(unsigned long private)
{ {
struct db9 *db9 = (void *) private; struct db9 *db9 = (void *) private;
struct parport *port = db9->pd->port; struct parport *port = db9->pd->port;
struct input_dev *dev = db9->dev; struct input_dev *dev = db9->dev[0];
struct input_dev *dev2 = db9->dev[1];
int data, i; int data, i;
switch(db9->mode) { switch (db9->mode) {
case DB9_MULTI_0802_2: case DB9_MULTI_0802_2:
data = parport_read_data(port) >> 3; data = parport_read_data(port) >> 3;
input_report_abs(dev + 1, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1)); input_report_abs(dev2, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1));
input_report_abs(dev + 1, ABS_Y, (data & DB9_DOWN ? 0 : 1) - (data & DB9_UP ? 0 : 1)); input_report_abs(dev2, ABS_Y, (data & DB9_DOWN ? 0 : 1) - (data & DB9_UP ? 0 : 1));
input_report_key(dev + 1, BTN_TRIGGER, ~data & DB9_FIRE1); input_report_key(dev2, BTN_TRIGGER, ~data & DB9_FIRE1);
case DB9_MULTI_0802: case DB9_MULTI_0802:
...@@ -405,7 +422,7 @@ static void db9_timer(unsigned long private) ...@@ -405,7 +422,7 @@ static void db9_timer(unsigned long private)
input_report_key(dev, BTN_C, ~data & DB9_FIRE2); input_report_key(dev, BTN_C, ~data & DB9_FIRE2);
parport_write_control(port, DB9_NORMAL); parport_write_control(port, DB9_NORMAL);
data=parport_read_data(port); data = parport_read_data(port);
input_report_key(dev, BTN_A, ~data & DB9_FIRE1); input_report_key(dev, BTN_A, ~data & DB9_FIRE1);
input_report_key(dev, BTN_START, ~data & DB9_FIRE2); input_report_key(dev, BTN_START, ~data & DB9_FIRE2);
...@@ -414,7 +431,7 @@ static void db9_timer(unsigned long private) ...@@ -414,7 +431,7 @@ static void db9_timer(unsigned long private)
case DB9_GENESIS5_PAD: case DB9_GENESIS5_PAD:
parport_write_control(port, DB9_NOSELECT); parport_write_control(port, DB9_NOSELECT);
data=parport_read_data(port); data = parport_read_data(port);
input_report_abs(dev, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1)); input_report_abs(dev, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1));
input_report_abs(dev, ABS_Y, (data & DB9_DOWN ? 0 : 1) - (data & DB9_UP ? 0 : 1)); 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,7 +439,7 @@ static void db9_timer(unsigned long private)
input_report_key(dev, BTN_C, ~data & DB9_FIRE2); input_report_key(dev, BTN_C, ~data & DB9_FIRE2);
parport_write_control(port, DB9_NORMAL); parport_write_control(port, DB9_NORMAL);
data=parport_read_data(port); data = parport_read_data(port);
input_report_key(dev, BTN_A, ~data & DB9_FIRE1); input_report_key(dev, BTN_A, ~data & DB9_FIRE1);
input_report_key(dev, BTN_X, ~data & DB9_FIRE2); input_report_key(dev, BTN_X, ~data & DB9_FIRE2);
...@@ -434,7 +451,7 @@ static void db9_timer(unsigned long private) ...@@ -434,7 +451,7 @@ static void db9_timer(unsigned long private)
parport_write_control(port, DB9_NOSELECT); /* 1 */ parport_write_control(port, DB9_NOSELECT); /* 1 */
udelay(DB9_GENESIS6_DELAY); udelay(DB9_GENESIS6_DELAY);
data=parport_read_data(port); data = parport_read_data(port);
input_report_abs(dev, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1)); input_report_abs(dev, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1));
input_report_abs(dev, ABS_Y, (data & DB9_DOWN ? 0 : 1) - (data & DB9_UP ? 0 : 1)); 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,7 +460,7 @@ static void db9_timer(unsigned long private)
parport_write_control(port, DB9_NORMAL); parport_write_control(port, DB9_NORMAL);
udelay(DB9_GENESIS6_DELAY); udelay(DB9_GENESIS6_DELAY);
data=parport_read_data(port); data = parport_read_data(port);
input_report_key(dev, BTN_A, ~data & DB9_FIRE1); input_report_key(dev, BTN_A, ~data & DB9_FIRE1);
input_report_key(dev, BTN_START, ~data & DB9_FIRE2); input_report_key(dev, BTN_START, ~data & DB9_FIRE2);
...@@ -477,7 +494,7 @@ static void db9_timer(unsigned long private) ...@@ -477,7 +494,7 @@ static void db9_timer(unsigned long private)
case DB9_CD32_PAD: case DB9_CD32_PAD:
data=parport_read_data(port); data = parport_read_data(port);
input_report_abs(dev, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1)); input_report_abs(dev, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1));
input_report_abs(dev, ABS_Y, (data & DB9_DOWN ? 0 : 1) - (data & DB9_UP ? 0 : 1)); input_report_abs(dev, ABS_Y, (data & DB9_DOWN ? 0 : 1) - (data & DB9_UP ? 0 : 1));
...@@ -513,7 +530,7 @@ static int db9_open(struct input_dev *dev) ...@@ -513,7 +530,7 @@ static int db9_open(struct input_dev *dev)
if (!db9->used++) { if (!db9->used++) {
parport_claim(db9->pd); parport_claim(db9->pd);
parport_write_data(port, 0xff); parport_write_data(port, 0xff);
if (db9_reverse[db9->mode]) { if (db9_modes[db9->mode].reverse) {
parport_data_reverse(port); parport_data_reverse(port);
parport_write_control(port, DB9_NORMAL); parport_write_control(port, DB9_NORMAL);
} }
...@@ -539,117 +556,160 @@ static void db9_close(struct input_dev *dev) ...@@ -539,117 +556,160 @@ static void db9_close(struct input_dev *dev)
up(&db9->sem); up(&db9->sem);
} }
static struct db9 __init *db9_probe(int *config, int nargs) static struct db9 __init *db9_probe(int parport, int mode)
{ {
struct db9 *db9; struct db9 *db9;
const struct db9_mode_data *db9_mode;
struct parport *pp; struct parport *pp;
struct pardevice *pd;
struct input_dev *input_dev;
int i, j; int i, j;
int err;
if (config[0] < 0) if (mode < 1 || mode >= DB9_MAX_PAD || !db9_modes[mode].n_buttons) {
return NULL; printk(KERN_ERR "db9.c: Bad device type %d\n", mode);
err = -EINVAL;
if (nargs < 2) { goto err_out;
printk(KERN_ERR "db9.c: Device type must be specified.\n");
return NULL;
} }
if (config[1] < 1 || config[1] >= DB9_MAX_PAD || !db9_buttons[config[1]]) { db9_mode = &db9_modes[mode];
printk(KERN_ERR "db9.c: bad config\n");
return NULL;
}
pp = parport_find_number(config[0]); pp = parport_find_number(parport);
if (!pp) { if (!pp) {
printk(KERN_ERR "db9.c: no such parport\n"); printk(KERN_ERR "db9.c: no such parport\n");
return NULL; err = -ENODEV;
goto err_out;
} }
if (db9_bidirectional[config[1]]) { if (db9_mode[mode].bidirectional && !(pp->modes & PARPORT_MODE_TRISTATE)) {
if (!(pp->modes & PARPORT_MODE_TRISTATE)) {
printk(KERN_ERR "db9.c: specified parport is not bidirectional\n"); printk(KERN_ERR "db9.c: specified parport is not bidirectional\n");
parport_put_port(pp); err = -EINVAL;
return NULL; goto err_put_pp;
} }
pd = parport_register_device(pp, "db9", NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL);
if (!pd) {
printk(KERN_ERR "db9.c: parport busy already - lp.o loaded?\n");
err = -EBUSY;
goto err_put_pp;
} }
if (!(db9 = kzalloc(sizeof(struct db9), GFP_KERNEL))) { db9 = kzalloc(sizeof(struct db9), GFP_KERNEL);
parport_put_port(pp); if (!db9) {
return NULL; printk(KERN_ERR "db9.c: Not enough memory\n");
err = -ENOMEM;
goto err_unreg_pardev;
} }
init_MUTEX(&db9->sem); init_MUTEX(&db9->sem);
db9->mode = config[1]; db9->pd = pd;
db9->mode = mode;
init_timer(&db9->timer); init_timer(&db9->timer);
db9->timer.data = (long) db9; db9->timer.data = (long) db9;
db9->timer.function = db9_timer; db9->timer.function = db9_timer;
db9->pd = parport_register_device(pp, "db9", NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL); for (i = 0; i < (min(db9_mode->n_pads, DB9_MAX_DEVICES)); i++) {
parport_put_port(pp);
if (!db9->pd) { db9->dev[i] = input_dev = input_allocate_device();
printk(KERN_ERR "db9.c: parport busy already - lp.o loaded?\n"); if (!input_dev) {
kfree(db9); printk(KERN_ERR "db9.c: Not enough memory for input device\n");
return NULL; err = -ENOMEM;
goto err_free_devs;
} }
for (i = 0; i < (min(db9_max_pads[db9->mode], DB9_MAX_DEVICES)); i++) {
sprintf(db9->phys[i], "%s/input%d", db9->pd->port->name, i); sprintf(db9->phys[i], "%s/input%d", db9->pd->port->name, i);
db9->dev[i].private = db9; input_dev->name = db9_mode->name;
db9->dev[i].open = db9_open; input_dev->phys = db9->phys[i];
db9->dev[i].close = db9_close; input_dev->id.bustype = BUS_PARPORT;
input_dev->id.vendor = 0x0002;
db9->dev[i].name = db9_name[db9->mode]; input_dev->id.product = mode;
db9->dev[i].phys = db9->phys[i]; input_dev->id.version = 0x0100;
db9->dev[i].id.bustype = BUS_PARPORT; input_dev->private = db9;
db9->dev[i].id.vendor = 0x0002;
db9->dev[i].id.product = config[1]; input_dev->open = db9_open;
db9->dev[i].id.version = 0x0100; input_dev->close = db9_close;
db9->dev[i].evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
for (j = 0; j < db9_buttons[db9->mode]; j++) for (j = 0; j < db9_mode->n_buttons; j++)
set_bit(db9_btn[db9->mode][j], db9->dev[i].keybit); set_bit(db9_mode->buttons[j], input_dev->keybit);
for (j = 0; j < db9_num_axis[db9->mode]; j++) { for (j = 0; j < db9_mode->n_axis; j++) {
set_bit(db9_abs[j], db9->dev[i].absbit); if (j < 2)
if (j < 2) { input_set_abs_params(input_dev, db9_abs[j], -1, 1, 0, 0);
db9->dev[i].absmin[db9_abs[j]] = -1; else
db9->dev[i].absmax[db9_abs[j]] = 1; input_set_abs_params(input_dev, db9_abs[j], 1, 255, 0, 0);
} else {
db9->dev[i].absmin[db9_abs[j]] = 1;
db9->dev[i].absmax[db9_abs[j]] = 255;
db9->dev[i].absflat[db9_abs[j]] = 0;
} }
}
input_register_device(db9->dev + i); input_register_device(input_dev);
printk(KERN_INFO "input: %s on %s\n", db9->dev[i].name, db9->pd->port->name);
} }
parport_put_port(pp);
return db9; return db9;
err_free_devs:
while (--i >= 0)
input_unregister_device(db9->dev[i]);
kfree(db9);
err_unreg_pardev:
parport_unregister_device(pd);
err_put_pp:
parport_put_port(pp);
err_out:
return ERR_PTR(err);
}
static void __exit db9_remove(struct db9 *db9)
{
int i;
for (i = 0; i < min(db9_modes[db9->mode].n_pads, DB9_MAX_DEVICES); i++)
input_unregister_device(db9->dev[i]);
parport_unregister_device(db9->pd);
kfree(db9);
} }
static int __init db9_init(void) static int __init db9_init(void)
{ {
db9_base[0] = db9_probe(db9, db9_nargs); int i;
db9_base[1] = db9_probe(db9_2, db9_nargs_2); int have_dev = 0;
db9_base[2] = db9_probe(db9_3, db9_nargs_3); int err = 0;
if (db9_base[0] || db9_base[1] || db9_base[2]) for (i = 0; i < DB9_MAX_PORTS; i++) {
return 0; if (db9[i].nargs == 0 || db9[i].args[DB9_ARG_PARPORT] < 0)
continue;
if (db9[i].nargs < 2) {
printk(KERN_ERR "db9.c: Device type must be specified.\n");
err = -EINVAL;
break;
}
db9_base[i] = db9_probe(db9[i].args[DB9_ARG_PARPORT],
db9[i].args[DB9_ARG_MODE]);
if (IS_ERR(db9_base[i])) {
err = PTR_ERR(db9_base[i]);
break;
}
return -ENODEV; have_dev = 1;
}
if (err) {
while (--i >= 0)
db9_remove(db9_base[i]);
return err;
}
return have_dev ? 0 : -ENODEV;
} }
static void __exit db9_exit(void) static void __exit db9_exit(void)
{ {
int i, j; int i;
for (i = 0; i < 3; i++) for (i = 0; i < DB9_MAX_PORTS; i++)
if (db9_base[i]) { if (db9_base[i])
for (j = 0; j < min(db9_max_pads[db9_base[i]->mode], DB9_MAX_DEVICES); j++) db9_remove(db9_base[i]);
input_unregister_device(db9_base[i]->dev + j);
parport_unregister_device(db9_base[i]->pd);
}
} }
module_init(db9_init); module_init(db9_init);
......
...@@ -41,20 +41,22 @@ MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); ...@@ -41,20 +41,22 @@ MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
MODULE_DESCRIPTION("NES, SNES, N64, MultiSystem, PSX gamepad driver"); MODULE_DESCRIPTION("NES, SNES, N64, MultiSystem, PSX gamepad driver");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
static int gc[] __initdata = { -1, 0, 0, 0, 0, 0 }; #define GC_MAX_PORTS 3
static int gc_nargs __initdata = 0; #define GC_MAX_DEVICES 5
module_param_array_named(map, gc, int, &gc_nargs, 0);
MODULE_PARM_DESC(map, "Describers first set of devices (<parport#>,<pad1>,<pad2>,..<pad5>)");
static int gc_2[] __initdata = { -1, 0, 0, 0, 0, 0 }; struct gc_config {
static int gc_nargs_2 __initdata = 0; int args[GC_MAX_DEVICES + 1];
module_param_array_named(map2, gc_2, int, &gc_nargs_2, 0); int nargs;
MODULE_PARM_DESC(map2, "Describers second set of devices"); };
static struct gc_config gc[GC_MAX_PORTS] __initdata;
static int gc_3[] __initdata = { -1, 0, 0, 0, 0, 0 }; module_param_array_named(map, gc[0].args, int, &gc[0].nargs, 0);
static int gc_nargs_3 __initdata = 0; MODULE_PARM_DESC(map, "Describes first set of devices (<parport#>,<pad1>,<pad2>,..<pad5>)");
module_param_array_named(map3, gc_3, int, &gc_nargs_3, 0); module_param_array_named(map2, gc[1].args, int, &gc[1].nargs, 0);
MODULE_PARM_DESC(map3, "Describers third set of devices"); MODULE_PARM_DESC(map2, "Describes second set of devices");
module_param_array_named(map3, gc[2].args, int, &gc[2].nargs, 0);
MODULE_PARM_DESC(map3, "Describes third set of devices");
__obsolete_setup("gc="); __obsolete_setup("gc=");
__obsolete_setup("gc_2="); __obsolete_setup("gc_2=");
...@@ -77,12 +79,12 @@ __obsolete_setup("gc_3="); ...@@ -77,12 +79,12 @@ __obsolete_setup("gc_3=");
struct gc { struct gc {
struct pardevice *pd; struct pardevice *pd;
struct input_dev dev[5]; struct input_dev *dev[GC_MAX_DEVICES];
struct timer_list timer; struct timer_list timer;
unsigned char pads[GC_MAX + 1]; unsigned char pads[GC_MAX + 1];
int used; int used;
struct semaphore sem; struct semaphore sem;
char phys[5][32]; char phys[GC_MAX_DEVICES][32];
}; };
static struct gc *gc_base[3]; 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,7 +332,6 @@ static void gc_psx_read_packet(struct gc *gc, unsigned char data[5][GC_PSX_BYTES
static void gc_timer(unsigned long private) static void gc_timer(unsigned long private)
{ {
struct gc *gc = (void *) private; struct gc *gc = (void *) private;
struct input_dev *dev = gc->dev;
unsigned char data[GC_MAX_LENGTH]; unsigned char data[GC_MAX_LENGTH];
unsigned char data_psx[5][GC_PSX_BYTES]; unsigned char data_psx[5][GC_PSX_BYTES];
int i, j, s; int i, j, s;
...@@ -357,16 +358,16 @@ static void gc_timer(unsigned long private) ...@@ -357,16 +358,16 @@ static void gc_timer(unsigned long private)
if (data[31 - j] & s) axes[1] |= 1 << j; if (data[31 - j] & s) axes[1] |= 1 << j;
} }
input_report_abs(dev + i, ABS_X, axes[0]); input_report_abs(gc->dev[i], ABS_X, axes[0]);
input_report_abs(dev + i, ABS_Y, -axes[1]); input_report_abs(gc->dev[i], ABS_Y, -axes[1]);
input_report_abs(dev + i, ABS_HAT0X, !(s & data[6]) - !(s & data[7])); input_report_abs(gc->dev[i], ABS_HAT0X, !(s & data[6]) - !(s & data[7]));
input_report_abs(dev + i, ABS_HAT0Y, !(s & data[4]) - !(s & data[5])); input_report_abs(gc->dev[i], ABS_HAT0Y, !(s & data[4]) - !(s & data[5]));
for (j = 0; j < 10; j++) for (j = 0; j < 10; j++)
input_report_key(dev + i, gc_n64_btn[j], s & data[gc_n64_bytes[j]]); input_report_key(gc->dev[i], gc_n64_btn[j], s & data[gc_n64_bytes[j]]);
input_sync(dev + i); input_sync(gc->dev[i]);
} }
} }
} }
...@@ -384,19 +385,19 @@ static void gc_timer(unsigned long private) ...@@ -384,19 +385,19 @@ static void gc_timer(unsigned long private)
s = gc_status_bit[i]; s = gc_status_bit[i];
if (s & (gc->pads[GC_NES] | gc->pads[GC_SNES])) { if (s & (gc->pads[GC_NES] | gc->pads[GC_SNES])) {
input_report_abs(dev + i, ABS_X, !(s & data[6]) - !(s & data[7])); input_report_abs(gc->dev[i], ABS_X, !(s & data[6]) - !(s & data[7]));
input_report_abs(dev + i, ABS_Y, !(s & data[4]) - !(s & data[5])); input_report_abs(gc->dev[i], ABS_Y, !(s & data[4]) - !(s & data[5]));
} }
if (s & gc->pads[GC_NES]) if (s & gc->pads[GC_NES])
for (j = 0; j < 4; j++) for (j = 0; j < 4; j++)
input_report_key(dev + i, gc_snes_btn[j], s & data[gc_nes_bytes[j]]); input_report_key(gc->dev[i], gc_snes_btn[j], s & data[gc_nes_bytes[j]]);
if (s & gc->pads[GC_SNES]) if (s & gc->pads[GC_SNES])
for (j = 0; j < 8; j++) for (j = 0; j < 8; j++)
input_report_key(dev + i, gc_snes_btn[j], s & data[gc_snes_bytes[j]]); input_report_key(gc->dev[i], gc_snes_btn[j], s & data[gc_snes_bytes[j]]);
input_sync(dev + i); input_sync(gc->dev[i]);
} }
} }
...@@ -413,15 +414,15 @@ static void gc_timer(unsigned long private) ...@@ -413,15 +414,15 @@ static void gc_timer(unsigned long private)
s = gc_status_bit[i]; s = gc_status_bit[i];
if (s & (gc->pads[GC_MULTI] | gc->pads[GC_MULTI2])) { if (s & (gc->pads[GC_MULTI] | gc->pads[GC_MULTI2])) {
input_report_abs(dev + i, ABS_X, !(s & data[2]) - !(s & data[3])); input_report_abs(gc->dev[i], ABS_X, !(s & data[2]) - !(s & data[3]));
input_report_abs(dev + i, ABS_Y, !(s & data[0]) - !(s & data[1])); input_report_abs(gc->dev[i], ABS_Y, !(s & data[0]) - !(s & data[1]));
input_report_key(dev + i, BTN_TRIGGER, s & data[4]); input_report_key(gc->dev[i], BTN_TRIGGER, s & data[4]);
} }
if (s & gc->pads[GC_MULTI2]) if (s & gc->pads[GC_MULTI2])
input_report_key(dev + i, BTN_THUMB, s & data[5]); input_report_key(gc->dev[i], BTN_THUMB, s & data[5]);
input_sync(dev + i); input_sync(gc->dev[i]);
} }
} }
...@@ -438,44 +439,44 @@ static void gc_timer(unsigned long private) ...@@ -438,44 +439,44 @@ static void gc_timer(unsigned long private)
case GC_PSX_RUMBLE: case GC_PSX_RUMBLE:
input_report_key(dev + i, BTN_THUMBL, ~data_psx[i][0] & 0x04); input_report_key(gc->dev[i], BTN_THUMBL, ~data_psx[i][0] & 0x04);
input_report_key(dev + i, BTN_THUMBR, ~data_psx[i][0] & 0x02); input_report_key(gc->dev[i], BTN_THUMBR, ~data_psx[i][0] & 0x02);
case GC_PSX_NEGCON: case GC_PSX_NEGCON:
case GC_PSX_ANALOG: case GC_PSX_ANALOG:
if(gc->pads[GC_DDR] & gc_status_bit[i]) { if (gc->pads[GC_DDR] & gc_status_bit[i]) {
for(j = 0; j < 4; j++) for(j = 0; j < 4; j++)
input_report_key(dev + i, gc_psx_ddr_btn[j], ~data_psx[i][0] & (0x10 << j)); input_report_key(gc->dev[i], gc_psx_ddr_btn[j], ~data_psx[i][0] & (0x10 << j));
} else { } else {
for (j = 0; j < 4; j++) for (j = 0; j < 4; j++)
input_report_abs(dev + i, gc_psx_abs[j+2], data_psx[i][j + 2]); input_report_abs(gc->dev[i], gc_psx_abs[j+2], data_psx[i][j + 2]);
input_report_abs(dev + i, ABS_X, 128 + !(data_psx[i][0] & 0x20) * 127 - !(data_psx[i][0] & 0x80) * 128); input_report_abs(gc->dev[i], ABS_X, 128 + !(data_psx[i][0] & 0x20) * 127 - !(data_psx[i][0] & 0x80) * 128);
input_report_abs(dev + i, ABS_Y, 128 + !(data_psx[i][0] & 0x40) * 127 - !(data_psx[i][0] & 0x10) * 128); input_report_abs(gc->dev[i], ABS_Y, 128 + !(data_psx[i][0] & 0x40) * 127 - !(data_psx[i][0] & 0x10) * 128);
} }
for (j = 0; j < 8; j++) for (j = 0; j < 8; j++)
input_report_key(dev + i, gc_psx_btn[j], ~data_psx[i][1] & (1 << j)); input_report_key(gc->dev[i], gc_psx_btn[j], ~data_psx[i][1] & (1 << j));
input_report_key(dev + i, BTN_START, ~data_psx[i][0] & 0x08); input_report_key(gc->dev[i], BTN_START, ~data_psx[i][0] & 0x08);
input_report_key(dev + i, BTN_SELECT, ~data_psx[i][0] & 0x01); input_report_key(gc->dev[i], BTN_SELECT, ~data_psx[i][0] & 0x01);
input_sync(dev + i); input_sync(gc->dev[i]);
break; break;
case GC_PSX_NORMAL: case GC_PSX_NORMAL:
if(gc->pads[GC_DDR] & gc_status_bit[i]) { if (gc->pads[GC_DDR] & gc_status_bit[i]) {
for(j = 0; j < 4; j++) for(j = 0; j < 4; j++)
input_report_key(dev + i, gc_psx_ddr_btn[j], ~data_psx[i][0] & (0x10 << j)); input_report_key(gc->dev[i], gc_psx_ddr_btn[j], ~data_psx[i][0] & (0x10 << j));
} else { } else {
input_report_abs(dev + i, ABS_X, 128 + !(data_psx[i][0] & 0x20) * 127 - !(data_psx[i][0] & 0x80) * 128); input_report_abs(gc->dev[i], ABS_X, 128 + !(data_psx[i][0] & 0x20) * 127 - !(data_psx[i][0] & 0x80) * 128);
input_report_abs(dev + i, ABS_Y, 128 + !(data_psx[i][0] & 0x40) * 127 - !(data_psx[i][0] & 0x10) * 128); input_report_abs(gc->dev[i], ABS_Y, 128 + !(data_psx[i][0] & 0x40) * 127 - !(data_psx[i][0] & 0x10) * 128);
/* for some reason if the extra axes are left unset they drift */ /* for some reason if the extra axes are left unset they drift */
/* for (j = 0; j < 4; j++) /* for (j = 0; j < 4; j++)
input_report_abs(dev + i, gc_psx_abs[j+2], 128); input_report_abs(gc->dev[i], gc_psx_abs[j+2], 128);
* This needs to be debugged properly, * This needs to be debugged properly,
* maybe fuzz processing needs to be done in input_sync() * maybe fuzz processing needs to be done in input_sync()
* --vojtech * --vojtech
...@@ -483,12 +484,12 @@ static void gc_timer(unsigned long private) ...@@ -483,12 +484,12 @@ static void gc_timer(unsigned long private)
} }
for (j = 0; j < 8; j++) for (j = 0; j < 8; j++)
input_report_key(dev + i, gc_psx_btn[j], ~data_psx[i][1] & (1 << j)); input_report_key(gc->dev[i], gc_psx_btn[j], ~data_psx[i][1] & (1 << j));
input_report_key(dev + i, BTN_START, ~data_psx[i][0] & 0x08); input_report_key(gc->dev[i], BTN_START, ~data_psx[i][0] & 0x08);
input_report_key(dev + i, BTN_SELECT, ~data_psx[i][0] & 0x01); input_report_key(gc->dev[i], BTN_SELECT, ~data_psx[i][0] & 0x01);
input_sync(dev + i); input_sync(gc->dev[i]);
break; break;
...@@ -533,177 +534,212 @@ static void gc_close(struct input_dev *dev) ...@@ -533,177 +534,212 @@ static void gc_close(struct input_dev *dev)
up(&gc->sem); up(&gc->sem);
} }
static struct gc __init *gc_probe(int *config, int nargs) static int __init gc_setup_pad(struct gc *gc, int idx, int pad_type)
{ {
struct gc *gc; struct input_dev *input_dev;
struct parport *pp; int i;
int i, j;
if (config[0] < 0)
return NULL;
if (nargs < 2) {
printk(KERN_ERR "gamecon.c: at least one device must be specified\n");
return NULL;
}
pp = parport_find_number(config[0]);
if (!pp) { if (!pad_type)
printk(KERN_ERR "gamecon.c: no such parport\n"); return 0;
return NULL;
}
if (!(gc = kzalloc(sizeof(struct gc), GFP_KERNEL))) { if (pad_type < 1 || pad_type > GC_MAX) {
parport_put_port(pp); printk(KERN_WARNING "gamecon.c: Pad type %d unknown\n", pad_type);
return NULL; return -EINVAL;
} }
init_MUTEX(&gc->sem); gc->dev[idx] = input_dev = input_allocate_device();
if (!input_dev) {
gc->pd = parport_register_device(pp, "gamecon", NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL); printk(KERN_ERR "gamecon.c: Not enough memory for input device\n");
return -ENOMEM;
parport_put_port(pp);
if (!gc->pd) {
printk(KERN_ERR "gamecon.c: parport busy already - lp.o loaded?\n");
kfree(gc);
return NULL;
} }
parport_claim(gc->pd); input_dev->name = gc_names[pad_type];
input_dev->phys = gc->phys[idx];
init_timer(&gc->timer); input_dev->id.bustype = BUS_PARPORT;
gc->timer.data = (long) gc; input_dev->id.vendor = 0x0001;
gc->timer.function = gc_timer; input_dev->id.product = pad_type;
input_dev->id.version = 0x0100;
for (i = 0; i < nargs - 1; i++) { input_dev->private = gc;
if (!config[i + 1]) input_dev->open = gc_open;
continue; input_dev->close = gc_close;
if (config[i + 1] < 1 || config[i + 1] > GC_MAX) { input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
printk(KERN_WARNING "gamecon.c: Pad type %d unknown\n", config[i + 1]);
continue;
}
gc->dev[i].private = gc;
gc->dev[i].open = gc_open;
gc->dev[i].close = gc_close;
gc->dev[i].evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); for (i = 0; i < 2; i++)
input_set_abs_params(input_dev, ABS_X + i, -1, 1, 0, 0);
for (j = 0; j < 2; j++) { gc->pads[0] |= gc_status_bit[idx];
set_bit(ABS_X + j, gc->dev[i].absbit); gc->pads[pad_type] |= gc_status_bit[idx];
gc->dev[i].absmin[ABS_X + j] = -1;
gc->dev[i].absmax[ABS_X + j] = 1;
}
gc->pads[0] |= gc_status_bit[i]; switch (pad_type) {
gc->pads[config[i + 1]] |= gc_status_bit[i];
switch(config[i + 1]) {
case GC_N64: case GC_N64:
for (j = 0; j < 10; j++) for (i = 0; i < 10; i++)
set_bit(gc_n64_btn[j], gc->dev[i].keybit); set_bit(gc_n64_btn[i], input_dev->keybit);
for (j = 0; j < 2; j++) { for (i = 0; i < 2; i++) {
set_bit(ABS_X + j, gc->dev[i].absbit); input_set_abs_params(input_dev, ABS_X + i, -127, 126, 0, 2);
gc->dev[i].absmin[ABS_X + j] = -127; input_set_abs_params(input_dev, ABS_HAT0X + i, -1, 1, 0, 0);
gc->dev[i].absmax[ABS_X + j] = 126;
gc->dev[i].absflat[ABS_X + j] = 2;
set_bit(ABS_HAT0X + j, gc->dev[i].absbit);
gc->dev[i].absmin[ABS_HAT0X + j] = -1;
gc->dev[i].absmax[ABS_HAT0X + j] = 1;
} }
break; break;
case GC_SNES: case GC_SNES:
for (j = 4; j < 8; j++) for (i = 4; i < 8; i++)
set_bit(gc_snes_btn[j], gc->dev[i].keybit); set_bit(gc_snes_btn[i], input_dev->keybit);
case GC_NES: case GC_NES:
for (j = 0; j < 4; j++) for (i = 0; i < 4; i++)
set_bit(gc_snes_btn[j], gc->dev[i].keybit); set_bit(gc_snes_btn[i], input_dev->keybit);
break; break;
case GC_MULTI2: case GC_MULTI2:
set_bit(BTN_THUMB, gc->dev[i].keybit); set_bit(BTN_THUMB, input_dev->keybit);
case GC_MULTI: case GC_MULTI:
set_bit(BTN_TRIGGER, gc->dev[i].keybit); set_bit(BTN_TRIGGER, input_dev->keybit);
break; break;
case GC_PSX: case GC_PSX:
for (i = 0; i < 6; i++)
input_set_abs_params(input_dev, gc_psx_abs[i], 4, 252, 0, 2);
for (i = 0; i < 12; i++)
set_bit(gc_psx_btn[i], input_dev->keybit);
break;
case GC_DDR: case GC_DDR:
if(config[i + 1] == GC_DDR) { for (i = 0; i < 4; i++)
for (j = 0; j < 4; j++) set_bit(gc_psx_ddr_btn[i], input_dev->keybit);
set_bit(gc_psx_ddr_btn[j], gc->dev[i].keybit); for (i = 0; i < 12; i++)
} else { set_bit(gc_psx_btn[i], input_dev->keybit);
for (j = 0; j < 6; j++) {
set_bit(gc_psx_abs[j], gc->dev[i].absbit); break;
gc->dev[i].absmin[gc_psx_abs[j]] = 4;
gc->dev[i].absmax[gc_psx_abs[j]] = 252;
gc->dev[i].absflat[gc_psx_abs[j]] = 2;
}
} }
for (j = 0; j < 12; j++) return 0;
set_bit(gc_psx_btn[j], gc->dev[i].keybit); }
break; static struct gc __init *gc_probe(int parport, int *pads, int n_pads)
{
struct gc *gc;
struct parport *pp;
struct pardevice *pd;
int i;
int err;
pp = parport_find_number(parport);
if (!pp) {
printk(KERN_ERR "gamecon.c: no such parport\n");
err = -EINVAL;
goto err_out;
} }
sprintf(gc->phys[i], "%s/input%d", gc->pd->port->name, i); pd = parport_register_device(pp, "gamecon", NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL);
if (!pd) {
printk(KERN_ERR "gamecon.c: parport busy already - lp.o loaded?\n");
err = -EBUSY;
goto err_put_pp;
}
gc->dev[i].name = gc_names[config[i + 1]]; gc = kzalloc(sizeof(struct gc), GFP_KERNEL);
gc->dev[i].phys = gc->phys[i]; if (!gc) {
gc->dev[i].id.bustype = BUS_PARPORT; printk(KERN_ERR "gamecon.c: Not enough memory\n");
gc->dev[i].id.vendor = 0x0001; err = -ENOMEM;
gc->dev[i].id.product = config[i + 1]; goto err_unreg_pardev;
gc->dev[i].id.version = 0x0100;
} }
parport_release(gc->pd); init_MUTEX(&gc->sem);
gc->pd = pd;
init_timer(&gc->timer);
gc->timer.data = (long) gc;
gc->timer.function = gc_timer;
if (!gc->pads[0]) { for (i = 0; i < n_pads; i++) {
parport_unregister_device(gc->pd); if (!pads[i])
kfree(gc); continue;
return NULL;
sprintf(gc->phys[i], "%s/input%d", gc->pd->port->name, i);
err = gc_setup_pad(gc, i, pads[i]);
if (err)
goto err_free_devs;
input_register_device(gc->dev[i]);
} }
for (i = 0; i < 5; i++) if (!gc->pads[0]) {
if (gc->pads[0] & gc_status_bit[i]) { printk(KERN_ERR "gamecon.c: No valid devices specified\n");
input_register_device(gc->dev + i); err = -EINVAL;
printk(KERN_INFO "input: %s on %s\n", gc->dev[i].name, gc->pd->port->name); goto err_free_gc;
} }
parport_put_port(pp);
return gc; return gc;
err_free_devs:
while (--i >= 0)
input_unregister_device(gc->dev[i]);
err_free_gc:
kfree(gc);
err_unreg_pardev:
parport_unregister_device(pd);
err_put_pp:
parport_put_port(pp);
err_out:
return ERR_PTR(err);
}
static void __exit gc_remove(struct gc *gc)
{
int i;
for (i = 0; i < GC_MAX_DEVICES; i++)
if (gc->dev[i])
input_unregister_device(gc->dev[i]);
parport_unregister_device(gc->pd);
kfree(gc);
} }
static int __init gc_init(void) static int __init gc_init(void)
{ {
gc_base[0] = gc_probe(gc, gc_nargs); int i;
gc_base[1] = gc_probe(gc_2, gc_nargs_2); int have_dev = 0;
gc_base[2] = gc_probe(gc_3, gc_nargs_3); int err = 0;
if (gc_base[0] || gc_base[1] || gc_base[2]) for (i = 0; i < GC_MAX_PORTS; i++) {
return 0; if (gc[i].nargs == 0 || gc[i].args[0] < 0)
continue;
return -ENODEV; if (gc[i].nargs < 2) {
printk(KERN_ERR "gamecon.c: at least one device must be specified\n");
err = -EINVAL;
break;
}
gc_base[i] = gc_probe(gc[i].args[0], gc[i].args + 1, gc[i].nargs - 1);
if (IS_ERR(gc_base[i])) {
err = PTR_ERR(gc_base[i]);
break;
}
have_dev = 1;
}
if (err) {
while (--i >= 0)
gc_remove(gc_base[i]);
return err;
}
return have_dev ? 0 : -ENODEV;
} }
static void __exit gc_exit(void) static void __exit gc_exit(void)
{ {
int i, j; int i;
for (i = 0; i < 3; i++) for (i = 0; i < GC_MAX_PORTS; i++)
if (gc_base[i]) { if (gc_base[i])
for (j = 0; j < 5; j++) gc_remove(gc_base[i]);
if (gc_base[i]->pads[0] & gc_status_bit[j])
input_unregister_device(gc_base[i]->dev + j);
parport_unregister_device(gc_base[i]->pd);
}
} }
module_init(gc_init); module_init(gc_init);
......
...@@ -81,7 +81,7 @@ static short gf2k_seq_digital[] = { 590, 320, 860, 0 }; ...@@ -81,7 +81,7 @@ static short gf2k_seq_digital[] = { 590, 320, 860, 0 };
struct gf2k { struct gf2k {
struct gameport *gameport; struct gameport *gameport;
struct input_dev dev; struct input_dev *dev;
int reads; int reads;
int bads; int bads;
unsigned char id; unsigned char id;
...@@ -175,7 +175,7 @@ static int gf2k_get_bits(unsigned char *buf, int pos, int num, int shift) ...@@ -175,7 +175,7 @@ static int gf2k_get_bits(unsigned char *buf, int pos, int num, int shift)
static void gf2k_read(struct gf2k *gf2k, unsigned char *data) static void gf2k_read(struct gf2k *gf2k, unsigned char *data)
{ {
struct input_dev *dev = &gf2k->dev; struct input_dev *dev = gf2k->dev;
int i, t; int i, t;
for (i = 0; i < 4 && i < gf2k_axes[gf2k->id]; i++) for (i = 0; i < 4 && i < gf2k_axes[gf2k->id]; i++)
...@@ -239,13 +239,19 @@ static void gf2k_close(struct input_dev *dev) ...@@ -239,13 +239,19 @@ static void gf2k_close(struct input_dev *dev)
static int gf2k_connect(struct gameport *gameport, struct gameport_driver *drv) static int gf2k_connect(struct gameport *gameport, struct gameport_driver *drv)
{ {
struct gf2k *gf2k; struct gf2k *gf2k;
struct input_dev *input_dev;
unsigned char data[GF2K_LENGTH]; unsigned char data[GF2K_LENGTH];
int i, err; int i, err;
if (!(gf2k = kzalloc(sizeof(struct gf2k), GFP_KERNEL))) gf2k = kzalloc(sizeof(struct gf2k), GFP_KERNEL);
return -ENOMEM; input_dev = input_allocate_device();
if (!gf2k || !input_dev) {
err = -ENOMEM;
goto fail1;
}
gf2k->gameport = gameport; gf2k->gameport = gameport;
gf2k->dev = input_dev;
gameport_set_drvdata(gameport, gf2k); gameport_set_drvdata(gameport, gf2k);
...@@ -295,53 +301,52 @@ static int gf2k_connect(struct gameport *gameport, struct gameport_driver *drv) ...@@ -295,53 +301,52 @@ static int gf2k_connect(struct gameport *gameport, struct gameport_driver *drv)
gf2k->length = gf2k_lens[gf2k->id]; gf2k->length = gf2k_lens[gf2k->id];
init_input_dev(&gf2k->dev); input_dev->name = gf2k_names[gf2k->id];
input_dev->phys = gf2k->phys;
gf2k->dev.private = gf2k; input_dev->id.bustype = BUS_GAMEPORT;
gf2k->dev.open = gf2k_open; input_dev->id.vendor = GAMEPORT_ID_VENDOR_GENIUS;
gf2k->dev.close = gf2k_close; input_dev->id.product = gf2k->id;
gf2k->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); input_dev->id.version = 0x0100;
input_dev->cdev.dev = &gameport->dev;
input_dev->private = gf2k;
gf2k->dev.name = gf2k_names[gf2k->id]; input_dev->open = gf2k_open;
gf2k->dev.phys = gf2k->phys; input_dev->close = gf2k_close;
gf2k->dev.id.bustype = BUS_GAMEPORT; input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
gf2k->dev.id.vendor = GAMEPORT_ID_VENDOR_GENIUS;
gf2k->dev.id.product = gf2k->id;
gf2k->dev.id.version = 0x0100;
for (i = 0; i < gf2k_axes[gf2k->id]; i++) for (i = 0; i < gf2k_axes[gf2k->id]; i++)
set_bit(gf2k_abs[i], gf2k->dev.absbit); set_bit(gf2k_abs[i], input_dev->absbit);
for (i = 0; i < gf2k_hats[gf2k->id]; i++) { for (i = 0; i < gf2k_hats[gf2k->id]; i++) {
set_bit(ABS_HAT0X + i, gf2k->dev.absbit); set_bit(ABS_HAT0X + i, input_dev->absbit);
gf2k->dev.absmin[ABS_HAT0X + i] = -1; input_dev->absmin[ABS_HAT0X + i] = -1;
gf2k->dev.absmax[ABS_HAT0X + i] = 1; input_dev->absmax[ABS_HAT0X + i] = 1;
} }
for (i = 0; i < gf2k_joys[gf2k->id]; i++) for (i = 0; i < gf2k_joys[gf2k->id]; i++)
set_bit(gf2k_btn_joy[i], gf2k->dev.keybit); set_bit(gf2k_btn_joy[i], input_dev->keybit);
for (i = 0; i < gf2k_pads[gf2k->id]; i++) for (i = 0; i < gf2k_pads[gf2k->id]; i++)
set_bit(gf2k_btn_pad[i], gf2k->dev.keybit); set_bit(gf2k_btn_pad[i], input_dev->keybit);
gf2k_read_packet(gameport, gf2k->length, data); gf2k_read_packet(gameport, gf2k->length, data);
gf2k_read(gf2k, data); gf2k_read(gf2k, data);
for (i = 0; i < gf2k_axes[gf2k->id]; i++) { for (i = 0; i < gf2k_axes[gf2k->id]; i++) {
gf2k->dev.absmax[gf2k_abs[i]] = (i < 2) ? gf2k->dev.abs[gf2k_abs[i]] * 2 - 32 : input_dev->absmax[gf2k_abs[i]] = (i < 2) ? input_dev->abs[gf2k_abs[i]] * 2 - 32 :
gf2k->dev.abs[gf2k_abs[0]] + gf2k->dev.abs[gf2k_abs[1]] - 32; input_dev->abs[gf2k_abs[0]] + input_dev->abs[gf2k_abs[1]] - 32;
gf2k->dev.absmin[gf2k_abs[i]] = 32; input_dev->absmin[gf2k_abs[i]] = 32;
gf2k->dev.absfuzz[gf2k_abs[i]] = 8; input_dev->absfuzz[gf2k_abs[i]] = 8;
gf2k->dev.absflat[gf2k_abs[i]] = (i < 2) ? 24 : 0; input_dev->absflat[gf2k_abs[i]] = (i < 2) ? 24 : 0;
} }
input_register_device(&gf2k->dev); input_register_device(gf2k->dev);
printk(KERN_INFO "input: %s on %s\n", gf2k_names[gf2k->id], gameport->phys);
return 0; return 0;
fail2: gameport_close(gameport); fail2: gameport_close(gameport);
fail1: gameport_set_drvdata(gameport, NULL); fail1: gameport_set_drvdata(gameport, NULL);
input_free_device(input_dev);
kfree(gf2k); kfree(gf2k);
return err; return err;
} }
...@@ -350,7 +355,7 @@ static void gf2k_disconnect(struct gameport *gameport) ...@@ -350,7 +355,7 @@ static void gf2k_disconnect(struct gameport *gameport)
{ {
struct gf2k *gf2k = gameport_get_drvdata(gameport); struct gf2k *gf2k = gameport_get_drvdata(gameport);
input_unregister_device(&gf2k->dev); input_unregister_device(gf2k->dev);
gameport_close(gameport); gameport_close(gameport);
gameport_set_drvdata(gameport, NULL); gameport_set_drvdata(gameport, NULL);
kfree(gf2k); kfree(gf2k);
......
...@@ -55,7 +55,7 @@ MODULE_LICENSE("GPL"); ...@@ -55,7 +55,7 @@ MODULE_LICENSE("GPL");
struct grip { struct grip {
struct gameport *gameport; struct gameport *gameport;
struct input_dev dev[2]; struct input_dev *dev[2];
unsigned char mode[2]; unsigned char mode[2];
int reads; int reads;
int bads; int bads;
...@@ -190,7 +190,7 @@ static void grip_poll(struct gameport *gameport) ...@@ -190,7 +190,7 @@ static void grip_poll(struct gameport *gameport)
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
dev = grip->dev + i; dev = grip->dev[i];
grip->reads++; grip->reads++;
switch (grip->mode[i]) { switch (grip->mode[i]) {
...@@ -297,6 +297,7 @@ static void grip_close(struct input_dev *dev) ...@@ -297,6 +297,7 @@ static void grip_close(struct input_dev *dev)
static int grip_connect(struct gameport *gameport, struct gameport_driver *drv) static int grip_connect(struct gameport *gameport, struct gameport_driver *drv)
{ {
struct grip *grip; struct grip *grip;
struct input_dev *input_dev;
unsigned int data[GRIP_LENGTH_XT]; unsigned int data[GRIP_LENGTH_XT];
int i, j, t; int i, j, t;
int err; int err;
...@@ -339,48 +340,56 @@ static int grip_connect(struct gameport *gameport, struct gameport_driver *drv) ...@@ -339,48 +340,56 @@ static int grip_connect(struct gameport *gameport, struct gameport_driver *drv)
gameport_set_poll_handler(gameport, grip_poll); gameport_set_poll_handler(gameport, grip_poll);
gameport_set_poll_interval(gameport, 20); gameport_set_poll_interval(gameport, 20);
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++) {
if (grip->mode[i]) { if (!grip->mode[i])
continue;
sprintf(grip->phys[i], "%s/input%d", gameport->phys, i); grip->dev[i] = input_dev = input_allocate_device();
if (!input_dev) {
err = -ENOMEM;
goto fail3;
}
grip->dev[i].private = grip; sprintf(grip->phys[i], "%s/input%d", gameport->phys, i);
grip->dev[i].open = grip_open; input_dev->name = grip_name[grip->mode[i]];
grip->dev[i].close = grip_close; input_dev->phys = grip->phys[i];
input_dev->id.bustype = BUS_GAMEPORT;
input_dev->id.vendor = GAMEPORT_ID_VENDOR_GRAVIS;
input_dev->id.product = grip->mode[i];
input_dev->id.version = 0x0100;
input_dev->cdev.dev = &gameport->dev;
input_dev->private = grip;
grip->dev[i].name = grip_name[grip->mode[i]]; input_dev->open = grip_open;
grip->dev[i].phys = grip->phys[i]; input_dev->close = grip_close;
grip->dev[i].id.bustype = BUS_GAMEPORT;
grip->dev[i].id.vendor = GAMEPORT_ID_VENDOR_GRAVIS;
grip->dev[i].id.product = grip->mode[i];
grip->dev[i].id.version = 0x0100;
grip->dev[i].evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
for (j = 0; (t = grip_abs[grip->mode[i]][j]) >= 0; j++) { for (j = 0; (t = grip_abs[grip->mode[i]][j]) >= 0; j++) {
if (j < grip_cen[grip->mode[i]]) if (j < grip_cen[grip->mode[i]])
input_set_abs_params(&grip->dev[i], t, 14, 52, 1, 2); input_set_abs_params(input_dev, t, 14, 52, 1, 2);
else if (j < grip_anx[grip->mode[i]]) else if (j < grip_anx[grip->mode[i]])
input_set_abs_params(&grip->dev[i], t, 3, 57, 1, 0); input_set_abs_params(input_dev, t, 3, 57, 1, 0);
else else
input_set_abs_params(&grip->dev[i], t, -1, 1, 0, 0); input_set_abs_params(input_dev, t, -1, 1, 0, 0);
} }
for (j = 0; (t = grip_btn[grip->mode[i]][j]) >= 0; j++) for (j = 0; (t = grip_btn[grip->mode[i]][j]) >= 0; j++)
if (t > 0) if (t > 0)
set_bit(t, grip->dev[i].keybit); set_bit(t, input_dev->keybit);
printk(KERN_INFO "input: %s on %s\n", input_register_device(grip->dev[i]);
grip_name[grip->mode[i]], gameport->phys);
input_register_device(grip->dev + i);
} }
return 0; return 0;
fail2: gameport_close(gameport); fail3: for (i = 0; i < 2; i++)
fail1: gameport_set_drvdata(gameport, NULL); if (grip->dev[i])
input_unregister_device(grip->dev[i]);
fail2: gameport_close(gameport);
fail1: gameport_set_drvdata(gameport, NULL);
kfree(grip); kfree(grip);
return err; return err;
} }
...@@ -391,8 +400,8 @@ static void grip_disconnect(struct gameport *gameport) ...@@ -391,8 +400,8 @@ static void grip_disconnect(struct gameport *gameport)
int i; int i;
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
if (grip->mode[i]) if (grip->dev[i])
input_unregister_device(grip->dev + i); input_unregister_device(grip->dev[i]);
gameport_close(gameport); gameport_close(gameport);
gameport_set_drvdata(gameport, NULL); gameport_set_drvdata(gameport, NULL);
kfree(grip); kfree(grip);
......
...@@ -32,23 +32,37 @@ MODULE_LICENSE("GPL"); ...@@ -32,23 +32,37 @@ MODULE_LICENSE("GPL");
#define dbg(format, arg...) do {} while (0) #define dbg(format, arg...) do {} while (0)
#endif #endif
#define GRIP_MAX_PORTS 4
/* /*
* Grip multiport state * Grip multiport state
*/ */
struct grip_port {
struct input_dev *dev;
int mode;
int registered;
/* individual gamepad states */
int buttons;
int xaxes;
int yaxes;
int dirty; /* has the state been updated? */
};
struct grip_mp { struct grip_mp {
struct gameport *gameport; struct gameport *gameport;
struct input_dev dev[4]; struct grip_port *port[GRIP_MAX_PORTS];
int mode[4]; // struct input_dev *dev[4];
int registered[4]; // int mode[4];
// int registered[4];
int reads; int reads;
int bads; int bads;
/* individual gamepad states */ /* individual gamepad states */
int buttons[4]; // int buttons[4];
int xaxes[4]; // int xaxes[4];
int yaxes[4]; // int yaxes[4];
int dirty[4]; /* has the state been updated? */ // int dirty[4]; /* has the state been updated? */
}; };
/* /*
...@@ -85,16 +99,16 @@ struct grip_mp { ...@@ -85,16 +99,16 @@ struct grip_mp {
#define GRIP_MODE_GP 2 #define GRIP_MODE_GP 2
#define GRIP_MODE_C64 3 #define GRIP_MODE_C64 3
static int grip_btn_gp[] = { BTN_TR, BTN_TL, BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, -1 }; static const int grip_btn_gp[] = { BTN_TR, BTN_TL, BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, -1 };
static int grip_btn_c64[] = { BTN_JOYSTICK, -1 }; static const int grip_btn_c64[] = { BTN_JOYSTICK, -1 };
static int grip_abs_gp[] = { ABS_X, ABS_Y, -1 }; static const int grip_abs_gp[] = { ABS_X, ABS_Y, -1 };
static int grip_abs_c64[] = { ABS_X, ABS_Y, -1 }; static const int grip_abs_c64[] = { ABS_X, ABS_Y, -1 };
static int *grip_abs[] = { NULL, NULL, grip_abs_gp, grip_abs_c64 }; static const int *grip_abs[] = { NULL, NULL, grip_abs_gp, grip_abs_c64 };
static int *grip_btn[] = { NULL, NULL, grip_btn_gp, grip_btn_c64 }; static const int *grip_btn[] = { NULL, NULL, grip_btn_gp, grip_btn_c64 };
static char *grip_name[] = { NULL, NULL, "Gravis Grip Pad", "Commodore 64 Joystick" }; static const char *grip_name[] = { NULL, NULL, "Gravis Grip Pad", "Commodore 64 Joystick" };
static const int init_seq[] = { static const int init_seq[] = {
1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1,
...@@ -104,9 +118,9 @@ static const int init_seq[] = { ...@@ -104,9 +118,9 @@ static const int init_seq[] = {
/* Maps multiport directional values to X,Y axis values (each axis encoded in 3 bits) */ /* Maps multiport directional values to X,Y axis values (each axis encoded in 3 bits) */
static int axis_map[] = { 5, 9, 1, 5, 6, 10, 2, 6, 4, 8, 0, 4, 5, 9, 1, 5 }; static const int axis_map[] = { 5, 9, 1, 5, 6, 10, 2, 6, 4, 8, 0, 4, 5, 9, 1, 5 };
static void register_slot(int i, struct grip_mp *grip); static int register_slot(int i, struct grip_mp *grip);
/* /*
* Returns whether an odd or even number of bits are on in pkt. * Returns whether an odd or even number of bits are on in pkt.
...@@ -353,9 +367,10 @@ static int dig_mode_start(struct gameport *gameport, u32 *packet) ...@@ -353,9 +367,10 @@ static int dig_mode_start(struct gameport *gameport, u32 *packet)
static int get_and_decode_packet(struct grip_mp *grip, int flags) static int get_and_decode_packet(struct grip_mp *grip, int flags)
{ {
struct grip_port *port;
u32 packet; u32 packet;
int joytype = 0; int joytype = 0;
int slot = 0; int slot;
/* Get a packet and check for validity */ /* Get a packet and check for validity */
...@@ -377,6 +392,8 @@ static int get_and_decode_packet(struct grip_mp *grip, int flags) ...@@ -377,6 +392,8 @@ static int get_and_decode_packet(struct grip_mp *grip, int flags)
if ((slot < 0) || (slot > 3)) if ((slot < 0) || (slot > 3))
return flags; return flags;
port = grip->port[slot];
/* /*
* Handle "reset" packets, which occur at startup, and when gamepads * Handle "reset" packets, which occur at startup, and when gamepads
* are removed or plugged in. May contain configuration of a new gamepad. * are removed or plugged in. May contain configuration of a new gamepad.
...@@ -385,14 +402,14 @@ static int get_and_decode_packet(struct grip_mp *grip, int flags) ...@@ -385,14 +402,14 @@ static int get_and_decode_packet(struct grip_mp *grip, int flags)
joytype = (packet >> 16) & 0x1f; joytype = (packet >> 16) & 0x1f;
if (!joytype) { if (!joytype) {
if (grip->registered[slot]) { if (port->registered) {
printk(KERN_INFO "grip_mp: removing %s, slot %d\n", printk(KERN_INFO "grip_mp: removing %s, slot %d\n",
grip_name[grip->mode[slot]], slot); grip_name[port->mode], slot);
input_unregister_device(grip->dev + slot); input_unregister_device(port->dev);
grip->registered[slot] = 0; port->registered = 0;
} }
dbg("Reset: grip multiport slot %d\n", slot); dbg("Reset: grip multiport slot %d\n", slot);
grip->mode[slot] = GRIP_MODE_RESET; port->mode = GRIP_MODE_RESET;
flags |= IO_SLOT_CHANGE; flags |= IO_SLOT_CHANGE;
return flags; return flags;
} }
...@@ -402,17 +419,17 @@ static int get_and_decode_packet(struct grip_mp *grip, int flags) ...@@ -402,17 +419,17 @@ static int get_and_decode_packet(struct grip_mp *grip, int flags)
if (joytype == 0x1f) { if (joytype == 0x1f) {
int dir = (packet >> 8) & 0xf; /* eight way directional value */ int dir = (packet >> 8) & 0xf; /* eight way directional value */
grip->buttons[slot] = (~packet) & 0xff; port->buttons = (~packet) & 0xff;
grip->yaxes[slot] = ((axis_map[dir] >> 2) & 3) - 1; port->yaxes = ((axis_map[dir] >> 2) & 3) - 1;
grip->xaxes[slot] = (axis_map[dir] & 3) - 1; port->xaxes = (axis_map[dir] & 3) - 1;
grip->dirty[slot] = 1; port->dirty = 1;
if (grip->mode[slot] == GRIP_MODE_RESET) if (port->mode == GRIP_MODE_RESET)
flags |= IO_SLOT_CHANGE; flags |= IO_SLOT_CHANGE;
grip->mode[slot] = GRIP_MODE_GP; port->mode = GRIP_MODE_GP;
if (!grip->registered[slot]) { if (!port->registered) {
dbg("New Grip pad in multiport slot %d.\n", slot); dbg("New Grip pad in multiport slot %d.\n", slot);
register_slot(slot, grip); register_slot(slot, grip);
} }
...@@ -445,9 +462,9 @@ static int slots_valid(struct grip_mp *grip) ...@@ -445,9 +462,9 @@ static int slots_valid(struct grip_mp *grip)
return 0; return 0;
for (slot = 0; slot < 4; slot++) { for (slot = 0; slot < 4; slot++) {
if (grip->mode[slot] == GRIP_MODE_RESET) if (grip->port[slot]->mode == GRIP_MODE_RESET)
invalid = 1; invalid = 1;
if (grip->mode[slot] != GRIP_MODE_NONE) if (grip->port[slot]->mode != GRIP_MODE_NONE)
active = 1; active = 1;
} }
...@@ -484,7 +501,7 @@ static int multiport_init(struct grip_mp *grip) ...@@ -484,7 +501,7 @@ static int multiport_init(struct grip_mp *grip)
/* Get packets, store multiport state, and check state's validity */ /* Get packets, store multiport state, and check state's validity */
for (tries = 0; tries < 4096; tries++) { for (tries = 0; tries < 4096; tries++) {
if ( slots_valid(grip) ) { if (slots_valid(grip)) {
initialized = 1; initialized = 1;
break; break;
} }
...@@ -499,24 +516,24 @@ static int multiport_init(struct grip_mp *grip) ...@@ -499,24 +516,24 @@ static int multiport_init(struct grip_mp *grip)
static void report_slot(struct grip_mp *grip, int slot) static void report_slot(struct grip_mp *grip, int slot)
{ {
struct input_dev *dev = &(grip->dev[slot]); struct grip_port *port = grip->port[slot];
int i, buttons = grip->buttons[slot]; int i;
/* Store button states with linux input driver */ /* Store button states with linux input driver */
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
input_report_key(dev, grip_btn_gp[i], (buttons >> i) & 1); input_report_key(port->dev, grip_btn_gp[i], (port->buttons >> i) & 1);
/* Store axis states with linux driver */ /* Store axis states with linux driver */
input_report_abs(dev, ABS_X, grip->xaxes[slot]); input_report_abs(port->dev, ABS_X, port->xaxes);
input_report_abs(dev, ABS_Y, grip->yaxes[slot]); input_report_abs(port->dev, ABS_Y, port->yaxes);
/* Tell the receiver of the events to process them */ /* Tell the receiver of the events to process them */
input_sync(dev); input_sync(port->dev);
grip->dirty[slot] = 0; port->dirty = 0;
} }
/* /*
...@@ -540,7 +557,7 @@ static void grip_poll(struct gameport *gameport) ...@@ -540,7 +557,7 @@ static void grip_poll(struct gameport *gameport)
} }
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
if (grip->dirty[i]) if (grip->port[i]->dirty)
report_slot(grip, i); report_slot(grip, i);
} }
...@@ -571,35 +588,43 @@ static void grip_close(struct input_dev *dev) ...@@ -571,35 +588,43 @@ static void grip_close(struct input_dev *dev)
* Tell the linux input layer about a newly plugged-in gamepad. * Tell the linux input layer about a newly plugged-in gamepad.
*/ */
static void register_slot(int slot, struct grip_mp *grip) static int register_slot(int slot, struct grip_mp *grip)
{ {
struct grip_port *port = grip->port[slot];
struct input_dev *input_dev;
int j, t; int j, t;
grip->dev[slot].private = grip; port->dev = input_dev = input_allocate_device();
grip->dev[slot].open = grip_open; if (!input_dev)
grip->dev[slot].close = grip_close; return -ENOMEM;
grip->dev[slot].name = grip_name[grip->mode[slot]];
grip->dev[slot].id.bustype = BUS_GAMEPORT; input_dev->name = grip_name[port->mode];
grip->dev[slot].id.vendor = GAMEPORT_ID_VENDOR_GRAVIS; input_dev->id.bustype = BUS_GAMEPORT;
grip->dev[slot].id.product = 0x0100 + grip->mode[slot]; input_dev->id.vendor = GAMEPORT_ID_VENDOR_GRAVIS;
grip->dev[slot].id.version = 0x0100; input_dev->id.product = 0x0100 + port->mode;
grip->dev[slot].evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); input_dev->id.version = 0x0100;
input_dev->cdev.dev = &grip->gameport->dev;
input_dev->private = grip;
input_dev->open = grip_open;
input_dev->close = grip_close;
for (j = 0; (t = grip_abs[grip->mode[slot]][j]) >= 0; j++) input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
input_set_abs_params(&grip->dev[slot], t, -1, 1, 0, 0);
for (j = 0; (t = grip_btn[grip->mode[slot]][j]) >= 0; j++) for (j = 0; (t = grip_abs[port->mode][j]) >= 0; j++)
input_set_abs_params(input_dev, t, -1, 1, 0, 0);
for (j = 0; (t = grip_btn[port->mode][j]) >= 0; j++)
if (t > 0) if (t > 0)
set_bit(t, grip->dev[slot].keybit); set_bit(t, input_dev->keybit);
input_register_device(grip->dev + slot); input_register_device(port->dev);
grip->registered[slot] = 1; port->registered = 1;
if (grip->dirty[slot]) /* report initial state, if any */ if (port->dirty) /* report initial state, if any */
report_slot(grip, slot); report_slot(grip, slot);
printk(KERN_INFO "grip_mp: added %s, slot %d\n", return 0;
grip_name[grip->mode[slot]], slot);
} }
static int grip_connect(struct gameport *gameport, struct gameport_driver *drv) static int grip_connect(struct gameport *gameport, struct gameport_driver *drv)
...@@ -626,7 +651,7 @@ static int grip_connect(struct gameport *gameport, struct gameport_driver *drv) ...@@ -626,7 +651,7 @@ static int grip_connect(struct gameport *gameport, struct gameport_driver *drv)
goto fail2; goto fail2;
} }
if (!grip->mode[0] && !grip->mode[1] && !grip->mode[2] && !grip->mode[3]) { if (!grip->port[0]->mode && !grip->port[1]->mode && !grip->port[2]->mode && !grip->port[3]->mode) {
/* nothing plugged in */ /* nothing plugged in */
err = -ENODEV; err = -ENODEV;
goto fail2; goto fail2;
...@@ -646,8 +671,8 @@ static void grip_disconnect(struct gameport *gameport) ...@@ -646,8 +671,8 @@ static void grip_disconnect(struct gameport *gameport)
int i; int i;
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
if (grip->registered[i]) if (grip->port[i]->registered)
input_unregister_device(grip->dev + i); input_unregister_device(grip->port[i]->dev);
gameport_close(gameport); gameport_close(gameport);
gameport_set_drvdata(gameport, NULL); gameport_set_drvdata(gameport, NULL);
kfree(grip); kfree(grip);
......
...@@ -67,7 +67,7 @@ struct guillemot_type { ...@@ -67,7 +67,7 @@ struct guillemot_type {
struct guillemot { struct guillemot {
struct gameport *gameport; struct gameport *gameport;
struct input_dev dev; struct input_dev *dev;
int bads; int bads;
int reads; int reads;
struct guillemot_type *type; struct guillemot_type *type;
...@@ -123,7 +123,7 @@ static int guillemot_read_packet(struct gameport *gameport, u8 *data) ...@@ -123,7 +123,7 @@ static int guillemot_read_packet(struct gameport *gameport, u8 *data)
static void guillemot_poll(struct gameport *gameport) static void guillemot_poll(struct gameport *gameport)
{ {
struct guillemot *guillemot = gameport_get_drvdata(gameport); struct guillemot *guillemot = gameport_get_drvdata(gameport);
struct input_dev *dev = &guillemot->dev; struct input_dev *dev = guillemot->dev;
u8 data[GUILLEMOT_MAX_LENGTH]; u8 data[GUILLEMOT_MAX_LENGTH];
int i; int i;
...@@ -179,14 +179,20 @@ static void guillemot_close(struct input_dev *dev) ...@@ -179,14 +179,20 @@ static void guillemot_close(struct input_dev *dev)
static int guillemot_connect(struct gameport *gameport, struct gameport_driver *drv) static int guillemot_connect(struct gameport *gameport, struct gameport_driver *drv)
{ {
struct guillemot *guillemot; struct guillemot *guillemot;
struct input_dev *input_dev;
u8 data[GUILLEMOT_MAX_LENGTH]; u8 data[GUILLEMOT_MAX_LENGTH];
int i, t; int i, t;
int err; int err;
if (!(guillemot = kzalloc(sizeof(struct guillemot), GFP_KERNEL))) guillemot = kzalloc(sizeof(struct guillemot), GFP_KERNEL);
return -ENOMEM; input_dev = input_allocate_device();
if (!guillemot || !input_dev) {
err = -ENOMEM;
goto fail1;
}
guillemot->gameport = gameport; guillemot->gameport = gameport;
guillemot->dev = input_dev;
gameport_set_drvdata(gameport, guillemot); gameport_set_drvdata(gameport, guillemot);
...@@ -216,41 +222,40 @@ static int guillemot_connect(struct gameport *gameport, struct gameport_driver * ...@@ -216,41 +222,40 @@ static int guillemot_connect(struct gameport *gameport, struct gameport_driver *
gameport_set_poll_interval(gameport, 20); gameport_set_poll_interval(gameport, 20);
sprintf(guillemot->phys, "%s/input0", gameport->phys); sprintf(guillemot->phys, "%s/input0", gameport->phys);
guillemot->type = guillemot_type + i; guillemot->type = guillemot_type + i;
guillemot->dev.private = guillemot; input_dev->name = guillemot_type[i].name;
guillemot->dev.open = guillemot_open; input_dev->phys = guillemot->phys;
guillemot->dev.close = guillemot_close; input_dev->id.bustype = BUS_GAMEPORT;
input_dev->id.vendor = GAMEPORT_ID_VENDOR_GUILLEMOT;
input_dev->id.product = guillemot_type[i].id;
input_dev->id.version = (int)data[14] << 8 | data[15];
input_dev->cdev.dev = &gameport->dev;
input_dev->private = guillemot;
guillemot->dev.name = guillemot_type[i].name; input_dev->open = guillemot_open;
guillemot->dev.phys = guillemot->phys; input_dev->close = guillemot_close;
guillemot->dev.id.bustype = BUS_GAMEPORT;
guillemot->dev.id.vendor = GAMEPORT_ID_VENDOR_GUILLEMOT;
guillemot->dev.id.product = guillemot_type[i].id;
guillemot->dev.id.version = (int)data[14] << 8 | data[15];
guillemot->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
for (i = 0; (t = guillemot->type->abs[i]) >= 0; i++) for (i = 0; (t = guillemot->type->abs[i]) >= 0; i++)
input_set_abs_params(&guillemot->dev, t, 0, 255, 0, 0); input_set_abs_params(input_dev, t, 0, 255, 0, 0);
if (guillemot->type->hat) { if (guillemot->type->hat) {
input_set_abs_params(&guillemot->dev, ABS_HAT0X, -1, 1, 0, 0); input_set_abs_params(input_dev, ABS_HAT0X, -1, 1, 0, 0);
input_set_abs_params(&guillemot->dev, ABS_HAT0Y, -1, 1, 0, 0); input_set_abs_params(input_dev, ABS_HAT0Y, -1, 1, 0, 0);
} }
for (i = 0; (t = guillemot->type->btn[i]) >= 0; i++) for (i = 0; (t = guillemot->type->btn[i]) >= 0; i++)
set_bit(t, guillemot->dev.keybit); set_bit(t, input_dev->keybit);
input_register_device(&guillemot->dev); input_register_device(guillemot->dev);
printk(KERN_INFO "input: %s ver %d.%02d on %s\n",
guillemot->type->name, data[14], data[15], gameport->phys);
return 0; return 0;
fail2: gameport_close(gameport); fail2: gameport_close(gameport);
fail1: gameport_set_drvdata(gameport, NULL); fail1: gameport_set_drvdata(gameport, NULL);
input_free_device(input_dev);
kfree(guillemot); kfree(guillemot);
return err; return err;
} }
...@@ -260,7 +265,7 @@ static void guillemot_disconnect(struct gameport *gameport) ...@@ -260,7 +265,7 @@ static void guillemot_disconnect(struct gameport *gameport)
struct guillemot *guillemot = gameport_get_drvdata(gameport); struct guillemot *guillemot = gameport_get_drvdata(gameport);
printk(KERN_INFO "guillemot.c: Failed %d reads out of %d on %s\n", guillemot->reads, guillemot->bads, guillemot->phys); printk(KERN_INFO "guillemot.c: Failed %d reads out of %d on %s\n", guillemot->reads, guillemot->bads, guillemot->phys);
input_unregister_device(&guillemot->dev); input_unregister_device(guillemot->dev);
gameport_close(gameport); gameport_close(gameport);
kfree(guillemot); kfree(guillemot);
} }
......
...@@ -144,7 +144,7 @@ static int iforce_upload_effect(struct input_dev *dev, struct ff_effect *effect) ...@@ -144,7 +144,7 @@ static int iforce_upload_effect(struct input_dev *dev, struct ff_effect *effect)
int is_update; int is_update;
/* Check this effect type is supported by this device */ /* Check this effect type is supported by this device */
if (!test_bit(effect->type, iforce->dev.ffbit)) if (!test_bit(effect->type, iforce->dev->ffbit))
return -EINVAL; return -EINVAL;
/* /*
...@@ -152,30 +152,31 @@ static int iforce_upload_effect(struct input_dev *dev, struct ff_effect *effect) ...@@ -152,30 +152,31 @@ static int iforce_upload_effect(struct input_dev *dev, struct ff_effect *effect)
*/ */
if (effect->id == -1) { if (effect->id == -1) {
for (id=0; id < FF_EFFECTS_MAX; ++id) for (id = 0; id < FF_EFFECTS_MAX; ++id)
if (!test_and_set_bit(FF_CORE_IS_USED, iforce->core_effects[id].flags)) break; if (!test_and_set_bit(FF_CORE_IS_USED, iforce->core_effects[id].flags))
break;
if ( id == FF_EFFECTS_MAX || id >= iforce->dev.ff_effects_max) if (id == FF_EFFECTS_MAX || id >= iforce->dev->ff_effects_max)
return -ENOMEM; return -ENOMEM;
effect->id = id; effect->id = id;
iforce->core_effects[id].owner = current->pid; iforce->core_effects[id].owner = current->pid;
iforce->core_effects[id].flags[0] = (1<<FF_CORE_IS_USED); /* Only IS_USED bit must be set */ iforce->core_effects[id].flags[0] = (1 << FF_CORE_IS_USED); /* Only IS_USED bit must be set */
is_update = FALSE; is_update = FALSE;
} }
else { else {
/* We want to update an effect */ /* We want to update an effect */
if (!CHECK_OWNERSHIP(effect->id, iforce)) return -EACCES; if (!CHECK_OWNERSHIP(effect->id, iforce))
return -EACCES;
/* Parameter type cannot be updated */ /* Parameter type cannot be updated */
if (effect->type != iforce->core_effects[effect->id].effect.type) if (effect->type != iforce->core_effects[effect->id].effect.type)
return -EINVAL; return -EINVAL;
/* Check the effect is not already being updated */ /* Check the effect is not already being updated */
if (test_bit(FF_CORE_UPDATE, iforce->core_effects[effect->id].flags)) { if (test_bit(FF_CORE_UPDATE, iforce->core_effects[effect->id].flags))
return -EAGAIN; return -EAGAIN;
}
is_update = TRUE; is_update = TRUE;
} }
...@@ -339,15 +340,19 @@ void iforce_delete_device(struct iforce *iforce) ...@@ -339,15 +340,19 @@ void iforce_delete_device(struct iforce *iforce)
int iforce_init_device(struct iforce *iforce) int iforce_init_device(struct iforce *iforce)
{ {
struct input_dev *input_dev;
unsigned char c[] = "CEOV"; unsigned char c[] = "CEOV";
int i; int i;
input_dev = input_allocate_device();
if (input_dev)
return -ENOMEM;
init_waitqueue_head(&iforce->wait); init_waitqueue_head(&iforce->wait);
spin_lock_init(&iforce->xmit_lock); spin_lock_init(&iforce->xmit_lock);
init_MUTEX(&iforce->mem_mutex); init_MUTEX(&iforce->mem_mutex);
iforce->xmit.buf = iforce->xmit_data; iforce->xmit.buf = iforce->xmit_data;
iforce->dev = input_dev;
iforce->dev.ff_effects_max = 10;
/* /*
* Input device fields. * Input device fields.
...@@ -356,26 +361,27 @@ int iforce_init_device(struct iforce *iforce) ...@@ -356,26 +361,27 @@ int iforce_init_device(struct iforce *iforce)
switch (iforce->bus) { switch (iforce->bus) {
#ifdef CONFIG_JOYSTICK_IFORCE_USB #ifdef CONFIG_JOYSTICK_IFORCE_USB
case IFORCE_USB: case IFORCE_USB:
iforce->dev.id.bustype = BUS_USB; input_dev->id.bustype = BUS_USB;
iforce->dev.dev = &iforce->usbdev->dev; input_dev->cdev.dev = &iforce->usbdev->dev;
break; break;
#endif #endif
#ifdef CONFIG_JOYSTICK_IFORCE_232 #ifdef CONFIG_JOYSTICK_IFORCE_232
case IFORCE_232: case IFORCE_232:
iforce->dev.id.bustype = BUS_RS232; input_dev->id.bustype = BUS_RS232;
iforce->dev.dev = &iforce->serio->dev; input_dev->cdev.dev = &iforce->serio->dev;
break; break;
#endif #endif
} }
iforce->dev.private = iforce; input_dev->private = iforce;
iforce->dev.name = "Unknown I-Force device"; input_dev->name = "Unknown I-Force device";
iforce->dev.open = iforce_open; input_dev->open = iforce_open;
iforce->dev.close = iforce_release; input_dev->close = iforce_release;
iforce->dev.flush = iforce_flush; input_dev->flush = iforce_flush;
iforce->dev.event = iforce_input_event; input_dev->event = iforce_input_event;
iforce->dev.upload_effect = iforce_upload_effect; input_dev->upload_effect = iforce_upload_effect;
iforce->dev.erase_effect = iforce_erase_effect; input_dev->erase_effect = iforce_erase_effect;
input_dev->ff_effects_max = 10;
/* /*
* On-device memory allocation. * On-device memory allocation.
...@@ -399,7 +405,8 @@ int iforce_init_device(struct iforce *iforce) ...@@ -399,7 +405,8 @@ int iforce_init_device(struct iforce *iforce)
if (i == 20) { /* 5 seconds */ if (i == 20) { /* 5 seconds */
printk(KERN_ERR "iforce-main.c: Timeout waiting for response from device.\n"); printk(KERN_ERR "iforce-main.c: Timeout waiting for response from device.\n");
return -1; input_free_device(input_dev);
return -ENODEV;
} }
/* /*
...@@ -407,12 +414,12 @@ int iforce_init_device(struct iforce *iforce) ...@@ -407,12 +414,12 @@ int iforce_init_device(struct iforce *iforce)
*/ */
if (!iforce_get_id_packet(iforce, "M")) if (!iforce_get_id_packet(iforce, "M"))
iforce->dev.id.vendor = (iforce->edata[2] << 8) | iforce->edata[1]; input_dev->id.vendor = (iforce->edata[2] << 8) | iforce->edata[1];
else else
printk(KERN_WARNING "iforce-main.c: Device does not respond to id packet M\n"); printk(KERN_WARNING "iforce-main.c: Device does not respond to id packet M\n");
if (!iforce_get_id_packet(iforce, "P")) if (!iforce_get_id_packet(iforce, "P"))
iforce->dev.id.product = (iforce->edata[2] << 8) | iforce->edata[1]; input_dev->id.product = (iforce->edata[2] << 8) | iforce->edata[1];
else else
printk(KERN_WARNING "iforce-main.c: Device does not respond to id packet P\n"); printk(KERN_WARNING "iforce-main.c: Device does not respond to id packet P\n");
...@@ -422,15 +429,15 @@ int iforce_init_device(struct iforce *iforce) ...@@ -422,15 +429,15 @@ int iforce_init_device(struct iforce *iforce)
printk(KERN_WARNING "iforce-main.c: Device does not respond to id packet B\n"); printk(KERN_WARNING "iforce-main.c: Device does not respond to id packet B\n");
if (!iforce_get_id_packet(iforce, "N")) if (!iforce_get_id_packet(iforce, "N"))
iforce->dev.ff_effects_max = iforce->edata[1]; iforce->dev->ff_effects_max = iforce->edata[1];
else else
printk(KERN_WARNING "iforce-main.c: Device does not respond to id packet N\n"); printk(KERN_WARNING "iforce-main.c: Device does not respond to id packet N\n");
/* Check if the device can store more effects than the driver can really handle */ /* Check if the device can store more effects than the driver can really handle */
if (iforce->dev.ff_effects_max > FF_EFFECTS_MAX) { if (iforce->dev->ff_effects_max > FF_EFFECTS_MAX) {
printk(KERN_WARNING "input??: Device can handle %d effects, but N_EFFECTS_MAX is set to %d in iforce.h\n", printk(KERN_WARNING "input??: Device can handle %d effects, but N_EFFECTS_MAX is set to %d in iforce.h\n",
iforce->dev.ff_effects_max, FF_EFFECTS_MAX); iforce->dev->ff_effects_max, FF_EFFECTS_MAX);
iforce->dev.ff_effects_max = FF_EFFECTS_MAX; iforce->dev->ff_effects_max = FF_EFFECTS_MAX;
} }
/* /*
...@@ -453,29 +460,28 @@ int iforce_init_device(struct iforce *iforce) ...@@ -453,29 +460,28 @@ int iforce_init_device(struct iforce *iforce)
*/ */
for (i = 0; iforce_device[i].idvendor; i++) for (i = 0; iforce_device[i].idvendor; i++)
if (iforce_device[i].idvendor == iforce->dev.id.vendor && if (iforce_device[i].idvendor == input_dev->id.vendor &&
iforce_device[i].idproduct == iforce->dev.id.product) iforce_device[i].idproduct == input_dev->id.product)
break; break;
iforce->type = iforce_device + i; iforce->type = iforce_device + i;
iforce->dev.name = iforce->type->name; input_dev->name = iforce->type->name;
/* /*
* Set input device bitfields and ranges. * Set input device bitfields and ranges.
*/ */
iforce->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_FF) | BIT(EV_FF_STATUS); input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_FF) | BIT(EV_FF_STATUS);
for (i = 0; iforce->type->btn[i] >= 0; i++) { for (i = 0; iforce->type->btn[i] >= 0; i++) {
signed short t = iforce->type->btn[i]; signed short t = iforce->type->btn[i];
set_bit(t, iforce->dev.keybit); set_bit(t, input_dev->keybit);
} }
set_bit(BTN_DEAD, iforce->dev.keybit); set_bit(BTN_DEAD, input_dev->keybit);
for (i = 0; iforce->type->abs[i] >= 0; i++) { for (i = 0; iforce->type->abs[i] >= 0; i++) {
signed short t = iforce->type->abs[i]; signed short t = iforce->type->abs[i];
set_bit(t, iforce->dev.absbit);
switch (t) { switch (t) {
...@@ -483,52 +489,42 @@ int iforce_init_device(struct iforce *iforce) ...@@ -483,52 +489,42 @@ int iforce_init_device(struct iforce *iforce)
case ABS_Y: case ABS_Y:
case ABS_WHEEL: case ABS_WHEEL:
iforce->dev.absmax[t] = 1920; input_set_abs_params(input_dev, t, -1920, 1920, 16, 128);
iforce->dev.absmin[t] = -1920; set_bit(t, input_dev->ffbit);
iforce->dev.absflat[t] = 128;
iforce->dev.absfuzz[t] = 16;
set_bit(t, iforce->dev.ffbit);
break; break;
case ABS_THROTTLE: case ABS_THROTTLE:
case ABS_GAS: case ABS_GAS:
case ABS_BRAKE: case ABS_BRAKE:
iforce->dev.absmax[t] = 255; input_set_abs_params(input_dev, t, 0, 255, 0, 0);
iforce->dev.absmin[t] = 0;
break; break;
case ABS_RUDDER: case ABS_RUDDER:
iforce->dev.absmax[t] = 127; input_set_abs_params(input_dev, t, -128, 127, 0, 0);
iforce->dev.absmin[t] = -128;
break; break;
case ABS_HAT0X: case ABS_HAT0X:
case ABS_HAT0Y: case ABS_HAT0Y:
case ABS_HAT1X: case ABS_HAT1X:
case ABS_HAT1Y: case ABS_HAT1Y:
iforce->dev.absmax[t] = 1;
iforce->dev.absmin[t] = -1; input_set_abs_params(input_dev, t, -1, 1, 0, 0);
break; break;
} }
} }
for (i = 0; iforce->type->ff[i] >= 0; i++) for (i = 0; iforce->type->ff[i] >= 0; i++)
set_bit(iforce->type->ff[i], iforce->dev.ffbit); set_bit(iforce->type->ff[i], input_dev->ffbit);
/* /*
* Register input device. * Register input device.
*/ */
input_register_device(&iforce->dev); input_register_device(iforce->dev);
printk(KERN_DEBUG "iforce->dev.open = %p\n", iforce->dev.open);
printk(KERN_INFO "input: %s [%d effects, %ld bytes memory]\n", printk(KERN_DEBUG "iforce->dev->open = %p\n", iforce->dev->open);
iforce->dev.name, iforce->dev.ff_effects_max,
iforce->device_memory.end);
return 0; return 0;
} }
......
...@@ -139,7 +139,8 @@ printk(KERN_DEBUG "iforce-packets.c: control_playback %d %d\n", id, value); ...@@ -139,7 +139,8 @@ printk(KERN_DEBUG "iforce-packets.c: control_playback %d %d\n", id, value);
static int mark_core_as_ready(struct iforce *iforce, unsigned short addr) static int mark_core_as_ready(struct iforce *iforce, unsigned short addr)
{ {
int i; int i;
for (i=0; i<iforce->dev.ff_effects_max; ++i) {
for (i = 0; i < iforce->dev->ff_effects_max; ++i) {
if (test_bit(FF_CORE_IS_USED, iforce->core_effects[i].flags) && if (test_bit(FF_CORE_IS_USED, iforce->core_effects[i].flags) &&
(iforce->core_effects[i].mod1_chunk.start == addr || (iforce->core_effects[i].mod1_chunk.start == addr ||
iforce->core_effects[i].mod2_chunk.start == addr)) { 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,7 +154,7 @@ static int mark_core_as_ready(struct iforce *iforce, unsigned short addr)
void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data, struct pt_regs *regs) void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data, struct pt_regs *regs)
{ {
struct input_dev *dev = &iforce->dev; struct input_dev *dev = iforce->dev;
int i; int i;
static int being_used = 0; static int being_used = 0;
......
...@@ -131,11 +131,10 @@ static int iforce_serio_connect(struct serio *serio, struct serio_driver *drv) ...@@ -131,11 +131,10 @@ static int iforce_serio_connect(struct serio *serio, struct serio_driver *drv)
struct iforce *iforce; struct iforce *iforce;
int err; int err;
if (!(iforce = kmalloc(sizeof(struct iforce), GFP_KERNEL))) iforce = kzalloc(sizeof(struct iforce), GFP_KERNEL);
if (!iforce)
return -ENOMEM; return -ENOMEM;
memset(iforce, 0, sizeof(struct iforce));
iforce->bus = IFORCE_232; iforce->bus = IFORCE_232;
iforce->serio = serio; iforce->serio = serio;
...@@ -148,7 +147,8 @@ static int iforce_serio_connect(struct serio *serio, struct serio_driver *drv) ...@@ -148,7 +147,8 @@ static int iforce_serio_connect(struct serio *serio, struct serio_driver *drv)
return err; return err;
} }
if (iforce_init_device(iforce)) { err = iforce_init_device(iforce);
if (err) {
serio_close(serio); serio_close(serio);
serio_set_drvdata(serio, NULL); serio_set_drvdata(serio, NULL);
kfree(iforce); kfree(iforce);
...@@ -162,7 +162,7 @@ static void iforce_serio_disconnect(struct serio *serio) ...@@ -162,7 +162,7 @@ static void iforce_serio_disconnect(struct serio *serio)
{ {
struct iforce *iforce = serio_get_drvdata(serio); struct iforce *iforce = serio_get_drvdata(serio);
input_unregister_device(&iforce->dev); input_unregister_device(iforce->dev);
serio_close(serio); serio_close(serio);
serio_set_drvdata(serio, NULL); serio_set_drvdata(serio, NULL);
kfree(iforce); kfree(iforce);
......
...@@ -135,28 +135,24 @@ static int iforce_usb_probe(struct usb_interface *intf, ...@@ -135,28 +135,24 @@ static int iforce_usb_probe(struct usb_interface *intf,
struct usb_host_interface *interface; struct usb_host_interface *interface;
struct usb_endpoint_descriptor *epirq, *epout; struct usb_endpoint_descriptor *epirq, *epout;
struct iforce *iforce; struct iforce *iforce;
int err = -ENOMEM;
interface = intf->cur_altsetting; interface = intf->cur_altsetting;
epirq = &interface->endpoint[0].desc; epirq = &interface->endpoint[0].desc;
epout = &interface->endpoint[1].desc; epout = &interface->endpoint[1].desc;
if (!(iforce = kmalloc(sizeof(struct iforce) + 32, GFP_KERNEL))) if (!(iforce = kzalloc(sizeof(struct iforce) + 32, GFP_KERNEL)))
goto fail; goto fail;
memset(iforce, 0, sizeof(struct iforce)); if (!(iforce->irq = usb_alloc_urb(0, GFP_KERNEL)))
if (!(iforce->irq = usb_alloc_urb(0, GFP_KERNEL))) {
goto fail; goto fail;
}
if (!(iforce->out = usb_alloc_urb(0, GFP_KERNEL))) { if (!(iforce->out = usb_alloc_urb(0, GFP_KERNEL)))
goto fail; goto fail;
}
if (!(iforce->ctrl = usb_alloc_urb(0, GFP_KERNEL))) { if (!(iforce->ctrl = usb_alloc_urb(0, GFP_KERNEL)))
goto fail; goto fail;
}
iforce->bus = IFORCE_USB; iforce->bus = IFORCE_USB;
iforce->usbdev = dev; iforce->usbdev = dev;
...@@ -174,7 +170,9 @@ static int iforce_usb_probe(struct usb_interface *intf, ...@@ -174,7 +170,9 @@ static int iforce_usb_probe(struct usb_interface *intf,
usb_fill_control_urb(iforce->ctrl, dev, usb_rcvctrlpipe(dev, 0), usb_fill_control_urb(iforce->ctrl, dev, usb_rcvctrlpipe(dev, 0),
(void*) &iforce->cr, iforce->edata, 16, iforce_usb_ctrl, iforce); (void*) &iforce->cr, iforce->edata, 16, iforce_usb_ctrl, iforce);
if (iforce_init_device(iforce)) goto fail; err = iforce_init_device(iforce);
if (err)
goto fail;
usb_set_intfdata(intf, iforce); usb_set_intfdata(intf, iforce);
return 0; return 0;
...@@ -187,7 +185,7 @@ static int iforce_usb_probe(struct usb_interface *intf, ...@@ -187,7 +185,7 @@ static int iforce_usb_probe(struct usb_interface *intf,
kfree(iforce); kfree(iforce);
} }
return -ENODEV; return err;
} }
/* Called by iforce_delete() */ /* Called by iforce_delete() */
...@@ -211,7 +209,7 @@ static void iforce_usb_disconnect(struct usb_interface *intf) ...@@ -211,7 +209,7 @@ static void iforce_usb_disconnect(struct usb_interface *intf)
usb_set_intfdata(intf, NULL); usb_set_intfdata(intf, NULL);
if (iforce) { if (iforce) {
iforce->usbdev = NULL; iforce->usbdev = NULL;
input_unregister_device(&iforce->dev); input_unregister_device(iforce->dev);
if (!open) { if (!open) {
iforce_delete_device(iforce); iforce_delete_device(iforce);
......
...@@ -117,7 +117,7 @@ struct iforce_device { ...@@ -117,7 +117,7 @@ struct iforce_device {
}; };
struct iforce { struct iforce {
struct input_dev dev; /* Input device interface */ struct input_dev *dev; /* Input device interface */
struct iforce_device *type; struct iforce_device *type;
int bus; int bus;
......
...@@ -54,7 +54,7 @@ MODULE_LICENSE("GPL"); ...@@ -54,7 +54,7 @@ MODULE_LICENSE("GPL");
struct interact { struct interact {
struct gameport *gameport; struct gameport *gameport;
struct input_dev dev; struct input_dev *dev;
int bads; int bads;
int reads; int reads;
unsigned char type; unsigned char type;
...@@ -130,7 +130,7 @@ static int interact_read_packet(struct gameport *gameport, int length, u32 *data ...@@ -130,7 +130,7 @@ static int interact_read_packet(struct gameport *gameport, int length, u32 *data
static void interact_poll(struct gameport *gameport) static void interact_poll(struct gameport *gameport)
{ {
struct interact *interact = gameport_get_drvdata(gameport); struct interact *interact = gameport_get_drvdata(gameport);
struct input_dev *dev = &interact->dev; struct input_dev *dev = interact->dev;
u32 data[3]; u32 data[3];
int i; int i;
...@@ -208,14 +208,20 @@ static void interact_close(struct input_dev *dev) ...@@ -208,14 +208,20 @@ static void interact_close(struct input_dev *dev)
static int interact_connect(struct gameport *gameport, struct gameport_driver *drv) static int interact_connect(struct gameport *gameport, struct gameport_driver *drv)
{ {
struct interact *interact; struct interact *interact;
struct input_dev *input_dev;
__u32 data[3]; __u32 data[3];
int i, t; int i, t;
int err; int err;
if (!(interact = kzalloc(sizeof(struct interact), GFP_KERNEL))) interact = kzalloc(sizeof(struct interact), GFP_KERNEL);
return -ENOMEM; input_dev = input_allocate_device();
if (!interact || !input_dev) {
err = -ENOMEM;
goto fail1;
}
interact->gameport = gameport; interact->gameport = gameport;
interact->dev = input_dev;
gameport_set_drvdata(gameport, interact); gameport_set_drvdata(gameport, interact);
...@@ -249,41 +255,40 @@ static int interact_connect(struct gameport *gameport, struct gameport_driver *d ...@@ -249,41 +255,40 @@ static int interact_connect(struct gameport *gameport, struct gameport_driver *d
interact->type = i; interact->type = i;
interact->length = interact_type[i].length; interact->length = interact_type[i].length;
interact->dev.private = interact; input_dev->name = interact_type[i].name;
interact->dev.open = interact_open; input_dev->phys = interact->phys;
interact->dev.close = interact_close; input_dev->id.bustype = BUS_GAMEPORT;
input_dev->id.vendor = GAMEPORT_ID_VENDOR_INTERACT;
input_dev->id.product = interact_type[i].id;
input_dev->id.version = 0x0100;
input_dev->private = interact;
interact->dev.name = interact_type[i].name; input_dev->open = interact_open;
interact->dev.phys = interact->phys; input_dev->close = interact_close;
interact->dev.id.bustype = BUS_GAMEPORT;
interact->dev.id.vendor = GAMEPORT_ID_VENDOR_INTERACT;
interact->dev.id.product = interact_type[i].id;
interact->dev.id.version = 0x0100;
interact->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
for (i = 0; (t = interact_type[interact->type].abs[i]) >= 0; i++) { for (i = 0; (t = interact_type[interact->type].abs[i]) >= 0; i++) {
set_bit(t, interact->dev.absbit); set_bit(t, input_dev->absbit);
if (i < interact_type[interact->type].b8) { if (i < interact_type[interact->type].b8) {
interact->dev.absmin[t] = 0; input_dev->absmin[t] = 0;
interact->dev.absmax[t] = 255; input_dev->absmax[t] = 255;
} else { } else {
interact->dev.absmin[t] = -1; input_dev->absmin[t] = -1;
interact->dev.absmax[t] = 1; input_dev->absmax[t] = 1;
} }
} }
for (i = 0; (t = interact_type[interact->type].btn[i]) >= 0; i++) for (i = 0; (t = interact_type[interact->type].btn[i]) >= 0; i++)
set_bit(t, interact->dev.keybit); set_bit(t, input_dev->keybit);
input_register_device(&interact->dev); input_register_device(interact->dev);
printk(KERN_INFO "input: %s on %s\n",
interact_type[interact->type].name, gameport->phys);
return 0; return 0;
fail2: gameport_close(gameport); fail2: gameport_close(gameport);
fail1: gameport_set_drvdata(gameport, NULL); fail1: gameport_set_drvdata(gameport, NULL);
input_free_device(input_dev);
kfree(interact); kfree(interact);
return err; return err;
} }
...@@ -292,7 +297,7 @@ static void interact_disconnect(struct gameport *gameport) ...@@ -292,7 +297,7 @@ static void interact_disconnect(struct gameport *gameport)
{ {
struct interact *interact = gameport_get_drvdata(gameport); struct interact *interact = gameport_get_drvdata(gameport);
input_unregister_device(&interact->dev); input_unregister_device(interact->dev);
gameport_close(gameport); gameport_close(gameport);
gameport_set_drvdata(gameport, NULL); gameport_set_drvdata(gameport, NULL);
kfree(interact); kfree(interact);
......
...@@ -49,14 +49,13 @@ MODULE_LICENSE("GPL"); ...@@ -49,14 +49,13 @@ MODULE_LICENSE("GPL");
static int magellan_buttons[] = { BTN_0, BTN_1, BTN_2, BTN_3, BTN_4, BTN_5, BTN_6, BTN_7, BTN_8 }; static int magellan_buttons[] = { BTN_0, BTN_1, BTN_2, BTN_3, BTN_4, BTN_5, BTN_6, BTN_7, BTN_8 };
static int magellan_axes[] = { ABS_X, ABS_Y, ABS_Z, ABS_RX, ABS_RY, ABS_RZ }; static int magellan_axes[] = { ABS_X, ABS_Y, ABS_Z, ABS_RX, ABS_RY, ABS_RZ };
static char *magellan_name = "LogiCad3D Magellan / SpaceMouse";
/* /*
* Per-Magellan data. * Per-Magellan data.
*/ */
struct magellan { struct magellan {
struct input_dev dev; struct input_dev *dev;
int idx; int idx;
unsigned char data[MAGELLAN_MAX_LENGTH]; unsigned char data[MAGELLAN_MAX_LENGTH];
char phys[32]; char phys[32];
...@@ -85,7 +84,7 @@ static int magellan_crunch_nibbles(unsigned char *data, int count) ...@@ -85,7 +84,7 @@ static int magellan_crunch_nibbles(unsigned char *data, int count)
static void magellan_process_packet(struct magellan* magellan, struct pt_regs *regs) static void magellan_process_packet(struct magellan* magellan, struct pt_regs *regs)
{ {
struct input_dev *dev = &magellan->dev; struct input_dev *dev = magellan->dev;
unsigned char *data = magellan->data; unsigned char *data = magellan->data;
int i, t; int i, t;
...@@ -138,9 +137,9 @@ static void magellan_disconnect(struct serio *serio) ...@@ -138,9 +137,9 @@ static void magellan_disconnect(struct serio *serio)
{ {
struct magellan* magellan = serio_get_drvdata(serio); struct magellan* magellan = serio_get_drvdata(serio);
input_unregister_device(&magellan->dev);
serio_close(serio); serio_close(serio);
serio_set_drvdata(serio, NULL); serio_set_drvdata(serio, NULL);
input_unregister_device(magellan->dev);
kfree(magellan); kfree(magellan);
} }
...@@ -153,52 +152,48 @@ static void magellan_disconnect(struct serio *serio) ...@@ -153,52 +152,48 @@ static void magellan_disconnect(struct serio *serio)
static int magellan_connect(struct serio *serio, struct serio_driver *drv) static int magellan_connect(struct serio *serio, struct serio_driver *drv)
{ {
struct magellan *magellan; struct magellan *magellan;
int i, t; struct input_dev *input_dev;
int err; int err = -ENOMEM;
int i;
if (!(magellan = kmalloc(sizeof(struct magellan), GFP_KERNEL))) magellan = kzalloc(sizeof(struct magellan), GFP_KERNEL);
return -ENOMEM; input_dev = input_allocate_device();
if (!magellan || !input_dev)
goto fail;
memset(magellan, 0, sizeof(struct magellan)); magellan->dev = input_dev;
sprintf(magellan->phys, "%s/input0", serio->phys);
magellan->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); input_dev->name = "LogiCad3D Magellan / SpaceMouse";
input_dev->phys = magellan->phys;
input_dev->id.bustype = BUS_RS232;
input_dev->id.vendor = SERIO_MAGELLAN;
input_dev->id.product = 0x0001;
input_dev->id.version = 0x0100;
input_dev->cdev.dev = &serio->dev;
input_dev->private = magellan;
for (i = 0; i < 9; i++) input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
set_bit(magellan_buttons[i], magellan->dev.keybit);
for (i = 0; i < 6; i++) {
t = magellan_axes[i];
set_bit(t, magellan->dev.absbit);
magellan->dev.absmin[t] = -360;
magellan->dev.absmax[t] = 360;
}
sprintf(magellan->phys, "%s/input0", serio->phys); for (i = 0; i < 9; i++)
set_bit(magellan_buttons[i], input_dev->keybit);
init_input_dev(&magellan->dev); for (i = 0; i < 6; i++)
magellan->dev.private = magellan; input_set_abs_params(input_dev, magellan_axes[i], -360, 360, 0, 0);
magellan->dev.name = magellan_name;
magellan->dev.phys = magellan->phys;
magellan->dev.id.bustype = BUS_RS232;
magellan->dev.id.vendor = SERIO_MAGELLAN;
magellan->dev.id.product = 0x0001;
magellan->dev.id.version = 0x0100;
magellan->dev.dev = &serio->dev;
serio_set_drvdata(serio, magellan); serio_set_drvdata(serio, magellan);
err = serio_open(serio, drv); err = serio_open(serio, drv);
if (err) { if (err)
serio_set_drvdata(serio, NULL); goto fail;
kfree(magellan);
return err;
}
input_register_device(&magellan->dev);
printk(KERN_INFO "input: %s on %s\n", magellan_name, serio->phys);
input_register_device(magellan->dev);
return 0; return 0;
fail: serio_set_drvdata(serio, NULL);
input_free_device(input_dev);
kfree(magellan);
return err;
} }
/* /*
......
...@@ -113,7 +113,7 @@ static struct { ...@@ -113,7 +113,7 @@ static struct {
struct sw { struct sw {
struct gameport *gameport; struct gameport *gameport;
struct input_dev dev[4]; struct input_dev *dev[4];
char name[64]; char name[64];
char phys[4][32]; char phys[4][32];
int length; int length;
...@@ -301,7 +301,7 @@ static int sw_check(__u64 t) ...@@ -301,7 +301,7 @@ static int sw_check(__u64 t)
static int sw_parse(unsigned char *buf, struct sw *sw) static int sw_parse(unsigned char *buf, struct sw *sw)
{ {
int hat, i, j; int hat, i, j;
struct input_dev *dev = sw->dev; struct input_dev *dev;
switch (sw->type) { switch (sw->type) {
...@@ -310,6 +310,8 @@ static int sw_parse(unsigned char *buf, struct sw *sw) ...@@ -310,6 +310,8 @@ static int sw_parse(unsigned char *buf, struct sw *sw)
if (sw_check(GB(0,64)) || (hat = (GB(6,1) << 3) | GB(60,3)) > 8) if (sw_check(GB(0,64)) || (hat = (GB(6,1) << 3) | GB(60,3)) > 8)
return -1; return -1;
dev = sw->dev[0];
input_report_abs(dev, ABS_X, (GB( 3,3) << 7) | GB(16,7)); input_report_abs(dev, ABS_X, (GB( 3,3) << 7) | GB(16,7));
input_report_abs(dev, ABS_Y, (GB( 0,3) << 7) | GB(24,7)); input_report_abs(dev, ABS_Y, (GB( 0,3) << 7) | GB(24,7));
input_report_abs(dev, ABS_RZ, (GB(35,2) << 7) | GB(40,7)); input_report_abs(dev, ABS_RZ, (GB(35,2) << 7) | GB(40,7));
...@@ -335,13 +337,13 @@ static int sw_parse(unsigned char *buf, struct sw *sw) ...@@ -335,13 +337,13 @@ static int sw_parse(unsigned char *buf, struct sw *sw)
if (sw_parity(GB(i*15,15))) if (sw_parity(GB(i*15,15)))
return -1; return -1;
input_report_abs(dev + i, ABS_X, GB(i*15+3,1) - GB(i*15+2,1)); input_report_abs(sw->dev[i], ABS_X, GB(i*15+3,1) - GB(i*15+2,1));
input_report_abs(dev + i, ABS_Y, GB(i*15+0,1) - GB(i*15+1,1)); input_report_abs(sw->dev[i], ABS_Y, GB(i*15+0,1) - GB(i*15+1,1));
for (j = 0; j < 10; j++) for (j = 0; j < 10; j++)
input_report_key(dev + i, sw_btn[SW_ID_GP][j], !GB(i*15+j+4,1)); input_report_key(sw->dev[i], sw_btn[SW_ID_GP][j], !GB(i*15+j+4,1));
input_sync(dev + i); input_sync(sw->dev[i]);
} }
return 0; return 0;
...@@ -352,6 +354,7 @@ static int sw_parse(unsigned char *buf, struct sw *sw) ...@@ -352,6 +354,7 @@ static int sw_parse(unsigned char *buf, struct sw *sw)
if (!sw_parity(GB(0,48)) || (hat = GB(42,4)) > 8) if (!sw_parity(GB(0,48)) || (hat = GB(42,4)) > 8)
return -1; return -1;
dev = sw->dev[0];
input_report_abs(dev, ABS_X, GB( 9,10)); input_report_abs(dev, ABS_X, GB( 9,10));
input_report_abs(dev, ABS_Y, GB(19,10)); input_report_abs(dev, ABS_Y, GB(19,10));
input_report_abs(dev, ABS_RZ, GB(36, 6)); input_report_abs(dev, ABS_RZ, GB(36, 6));
...@@ -372,6 +375,7 @@ static int sw_parse(unsigned char *buf, struct sw *sw) ...@@ -372,6 +375,7 @@ static int sw_parse(unsigned char *buf, struct sw *sw)
if (!sw_parity(GB(0,43)) || (hat = GB(28,4)) > 8) if (!sw_parity(GB(0,43)) || (hat = GB(28,4)) > 8)
return -1; return -1;
dev = sw->dev[0];
input_report_abs(dev, ABS_X, GB( 0,10)); input_report_abs(dev, ABS_X, GB( 0,10));
input_report_abs(dev, ABS_Y, GB(16,10)); input_report_abs(dev, ABS_Y, GB(16,10));
input_report_abs(dev, ABS_THROTTLE, GB(32, 6)); input_report_abs(dev, ABS_THROTTLE, GB(32, 6));
...@@ -396,6 +400,7 @@ static int sw_parse(unsigned char *buf, struct sw *sw) ...@@ -396,6 +400,7 @@ static int sw_parse(unsigned char *buf, struct sw *sw)
if (!sw_parity(GB(0,33))) if (!sw_parity(GB(0,33)))
return -1; return -1;
dev = sw->dev[0];
input_report_abs(dev, ABS_RX, GB( 0,10)); input_report_abs(dev, ABS_RX, GB( 0,10));
input_report_abs(dev, ABS_RUDDER, GB(10, 6)); input_report_abs(dev, ABS_RUDDER, GB(10, 6));
input_report_abs(dev, ABS_THROTTLE, GB(16, 6)); input_report_abs(dev, ABS_THROTTLE, GB(16, 6));
...@@ -581,6 +586,7 @@ static int sw_guess_mode(unsigned char *buf, int len) ...@@ -581,6 +586,7 @@ static int sw_guess_mode(unsigned char *buf, int len)
static int sw_connect(struct gameport *gameport, struct gameport_driver *drv) static int sw_connect(struct gameport *gameport, struct gameport_driver *drv)
{ {
struct sw *sw; struct sw *sw;
struct input_dev *input_dev;
int i, j, k, l; int i, j, k, l;
int err; int err;
unsigned char *buf = NULL; /* [SW_LENGTH] */ unsigned char *buf = NULL; /* [SW_LENGTH] */
...@@ -729,42 +735,50 @@ static int sw_connect(struct gameport *gameport, struct gameport_driver *drv) ...@@ -729,42 +735,50 @@ static int sw_connect(struct gameport *gameport, struct gameport_driver *drv)
sprintf(sw->name, "Microsoft SideWinder %s", sw_name[sw->type]); sprintf(sw->name, "Microsoft SideWinder %s", sw_name[sw->type]);
sprintf(sw->phys[i], "%s/input%d", gameport->phys, i); sprintf(sw->phys[i], "%s/input%d", gameport->phys, i);
sw->dev[i].private = sw; input_dev = input_allocate_device();
if (!input_dev) {
err = -ENOMEM;
goto fail3;
}
sw->dev[i].open = sw_open; input_dev->name = sw->name;
sw->dev[i].close = sw_close; input_dev->phys = sw->phys[i];
input_dev->id.bustype = BUS_GAMEPORT;
input_dev->id.vendor = GAMEPORT_ID_VENDOR_MICROSOFT;
input_dev->id.product = sw->type;
input_dev->id.version = 0x0100;
input_dev->cdev.dev = &gameport->dev;
input_dev->private = sw;
sw->dev[i].name = sw->name; input_dev->open = sw_open;
sw->dev[i].phys = sw->phys[i]; input_dev->close = sw_close;
sw->dev[i].id.bustype = BUS_GAMEPORT;
sw->dev[i].id.vendor = GAMEPORT_ID_VENDOR_MICROSOFT;
sw->dev[i].id.product = sw->type;
sw->dev[i].id.version = 0x0100;
sw->dev[i].evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
for (j = 0; (bits = sw_bit[sw->type][j]); j++) { for (j = 0; (bits = sw_bit[sw->type][j]); j++) {
code = sw_abs[sw->type][j]; code = sw_abs[sw->type][j];
set_bit(code, sw->dev[i].absbit); set_bit(code, input_dev->absbit);
sw->dev[i].absmax[code] = (1 << bits) - 1; input_dev->absmax[code] = (1 << bits) - 1;
sw->dev[i].absmin[code] = (bits == 1) ? -1 : 0; input_dev->absmin[code] = (bits == 1) ? -1 : 0;
sw->dev[i].absfuzz[code] = ((bits >> 1) >= 2) ? (1 << ((bits >> 1) - 2)) : 0; input_dev->absfuzz[code] = ((bits >> 1) >= 2) ? (1 << ((bits >> 1) - 2)) : 0;
if (code != ABS_THROTTLE) if (code != ABS_THROTTLE)
sw->dev[i].absflat[code] = (bits >= 5) ? (1 << (bits - 5)) : 0; input_dev->absflat[code] = (bits >= 5) ? (1 << (bits - 5)) : 0;
} }
for (j = 0; (code = sw_btn[sw->type][j]); j++) for (j = 0; (code = sw_btn[sw->type][j]); j++)
set_bit(code, sw->dev[i].keybit); set_bit(code, input_dev->keybit);
dbg("%s%s [%d-bit id %d data %d]\n", sw->name, comment, m, l, k);
input_register_device(sw->dev + i); input_register_device(sw->dev[i]);
printk(KERN_INFO "input: %s%s on %s [%d-bit id %d data %d]\n",
sw->name, comment, gameport->phys, m, l, k);
} }
return 0; return 0;
fail2: gameport_close(gameport); fail3: while (--i >= 0)
fail1: gameport_set_drvdata(gameport, NULL); input_unregister_device(sw->dev[i]);
fail2: gameport_close(gameport);
fail1: gameport_set_drvdata(gameport, NULL);
kfree(sw); kfree(sw);
kfree(buf); kfree(buf);
kfree(idbuf); kfree(idbuf);
...@@ -777,7 +791,7 @@ static void sw_disconnect(struct gameport *gameport) ...@@ -777,7 +791,7 @@ static void sw_disconnect(struct gameport *gameport)
int i; int i;
for (i = 0; i < sw->number; i++) for (i = 0; i < sw->number; i++)
input_unregister_device(sw->dev + i); input_unregister_device(sw->dev[i]);
gameport_close(gameport); gameport_close(gameport);
gameport_set_drvdata(gameport, NULL); gameport_set_drvdata(gameport, NULL);
kfree(sw); kfree(sw);
......
...@@ -70,8 +70,7 @@ static char *spaceball_names[] = { ...@@ -70,8 +70,7 @@ static char *spaceball_names[] = {
*/ */
struct spaceball { struct spaceball {
struct input_dev dev; struct input_dev *dev;
struct serio *serio;
int idx; int idx;
int escape; int escape;
unsigned char data[SPACEBALL_MAX_LENGTH]; unsigned char data[SPACEBALL_MAX_LENGTH];
...@@ -85,7 +84,7 @@ struct spaceball { ...@@ -85,7 +84,7 @@ struct spaceball {
static void spaceball_process_packet(struct spaceball* spaceball, struct pt_regs *regs) static void spaceball_process_packet(struct spaceball* spaceball, struct pt_regs *regs)
{ {
struct input_dev *dev = &spaceball->dev; struct input_dev *dev = spaceball->dev;
unsigned char *data = spaceball->data; unsigned char *data = spaceball->data;
int i; int i;
...@@ -193,9 +192,9 @@ static void spaceball_disconnect(struct serio *serio) ...@@ -193,9 +192,9 @@ static void spaceball_disconnect(struct serio *serio)
{ {
struct spaceball* spaceball = serio_get_drvdata(serio); struct spaceball* spaceball = serio_get_drvdata(serio);
input_unregister_device(&spaceball->dev);
serio_close(serio); serio_close(serio);
serio_set_drvdata(serio, NULL); serio_set_drvdata(serio, NULL);
input_unregister_device(spaceball->dev);
kfree(spaceball); kfree(spaceball);
} }
...@@ -208,69 +207,62 @@ static void spaceball_disconnect(struct serio *serio) ...@@ -208,69 +207,62 @@ static void spaceball_disconnect(struct serio *serio)
static int spaceball_connect(struct serio *serio, struct serio_driver *drv) static int spaceball_connect(struct serio *serio, struct serio_driver *drv)
{ {
struct spaceball *spaceball; struct spaceball *spaceball;
int i, t, id; struct input_dev *input_dev;
int err; int err = -ENOMEM;
int i, id;
if ((id = serio->id.id) > SPACEBALL_MAX_ID) if ((id = serio->id.id) > SPACEBALL_MAX_ID)
return -ENODEV; return -ENODEV;
if (!(spaceball = kmalloc(sizeof(struct spaceball), GFP_KERNEL))) spaceball = kmalloc(sizeof(struct spaceball), GFP_KERNEL);
return - ENOMEM; input_dev = input_allocate_device();
if (!spaceball || !input_dev)
goto fail;
memset(spaceball, 0, sizeof(struct spaceball)); spaceball->dev = input_dev;
sprintf(spaceball->phys, "%s/input0", serio->phys);
input_dev->name = spaceball_names[id];
input_dev->phys = spaceball->phys;
input_dev->id.bustype = BUS_RS232;
input_dev->id.vendor = SERIO_SPACEBALL;
input_dev->id.product = id;
input_dev->id.version = 0x0100;
input_dev->cdev.dev = &serio->dev;
input_dev->private = spaceball;
spaceball->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
switch (id) { switch (id) {
case SPACEBALL_4000FLX: case SPACEBALL_4000FLX:
case SPACEBALL_4000FLX_L: case SPACEBALL_4000FLX_L:
spaceball->dev.keybit[LONG(BTN_0)] |= BIT(BTN_9); input_dev->keybit[LONG(BTN_0)] |= BIT(BTN_9);
spaceball->dev.keybit[LONG(BTN_A)] |= BIT(BTN_A) | BIT(BTN_B) | BIT(BTN_C) | BIT(BTN_MODE); input_dev->keybit[LONG(BTN_A)] |= BIT(BTN_A) | BIT(BTN_B) | BIT(BTN_C) | BIT(BTN_MODE);
default: default:
spaceball->dev.keybit[LONG(BTN_0)] |= BIT(BTN_2) | BIT(BTN_3) | BIT(BTN_4) input_dev->keybit[LONG(BTN_0)] |= BIT(BTN_2) | BIT(BTN_3) | BIT(BTN_4)
| BIT(BTN_5) | BIT(BTN_6) | BIT(BTN_7) | BIT(BTN_8); | BIT(BTN_5) | BIT(BTN_6) | BIT(BTN_7) | BIT(BTN_8);
case SPACEBALL_3003C: case SPACEBALL_3003C:
spaceball->dev.keybit[LONG(BTN_0)] |= BIT(BTN_1) | BIT(BTN_8); input_dev->keybit[LONG(BTN_0)] |= BIT(BTN_1) | BIT(BTN_8);
} }
for (i = 0; i < 6; i++) { for (i = 0; i < 3; i++) {
t = spaceball_axes[i]; input_set_abs_params(input_dev, ABS_X + i, -8000, 8000, 8, 40);
set_bit(t, spaceball->dev.absbit); input_set_abs_params(input_dev, ABS_RX + i, -1600, 1600, 2, 8);
spaceball->dev.absmin[t] = i < 3 ? -8000 : -1600;
spaceball->dev.absmax[t] = i < 3 ? 8000 : 1600;
spaceball->dev.absflat[t] = i < 3 ? 40 : 8;
spaceball->dev.absfuzz[t] = i < 3 ? 8 : 2;
} }
spaceball->serio = serio;
spaceball->dev.private = spaceball;
sprintf(spaceball->phys, "%s/input0", serio->phys);
init_input_dev(&spaceball->dev);
spaceball->dev.name = spaceball_names[id];
spaceball->dev.phys = spaceball->phys;
spaceball->dev.id.bustype = BUS_RS232;
spaceball->dev.id.vendor = SERIO_SPACEBALL;
spaceball->dev.id.product = id;
spaceball->dev.id.version = 0x0100;
spaceball->dev.dev = &serio->dev;
serio_set_drvdata(serio, spaceball); serio_set_drvdata(serio, spaceball);
err = serio_open(serio, drv); err = serio_open(serio, drv);
if (err) { if (err)
serio_set_drvdata(serio, NULL); goto fail;
kfree(spaceball);
return err;
}
input_register_device(&spaceball->dev);
printk(KERN_INFO "input: %s on serio%s\n",
spaceball_names[id], serio->phys);
input_register_device(spaceball->dev);
return 0; return 0;
fail: serio_set_drvdata(serio, NULL);
input_free_device(input_dev);
kfree(spaceball);
return err;
} }
/* /*
......
...@@ -52,15 +52,13 @@ MODULE_LICENSE("GPL"); ...@@ -52,15 +52,13 @@ MODULE_LICENSE("GPL");
static int spaceorb_buttons[] = { BTN_TL, BTN_TR, BTN_Y, BTN_X, BTN_B, BTN_A }; static int spaceorb_buttons[] = { BTN_TL, BTN_TR, BTN_Y, BTN_X, BTN_B, BTN_A };
static int spaceorb_axes[] = { ABS_X, ABS_Y, ABS_Z, ABS_RX, ABS_RY, ABS_RZ }; static int spaceorb_axes[] = { ABS_X, ABS_Y, ABS_Z, ABS_RX, ABS_RY, ABS_RZ };
static char *spaceorb_name = "SpaceTec SpaceOrb 360 / Avenger";
/* /*
* Per-Orb data. * Per-Orb data.
*/ */
struct spaceorb { struct spaceorb {
struct input_dev dev; struct input_dev *dev;
struct serio *serio;
int idx; int idx;
unsigned char data[SPACEORB_MAX_LENGTH]; unsigned char data[SPACEORB_MAX_LENGTH];
char phys[32]; char phys[32];
...@@ -78,7 +76,7 @@ static unsigned char *spaceorb_errors[] = { "EEPROM storing 0 failed", "Receive ...@@ -78,7 +76,7 @@ static unsigned char *spaceorb_errors[] = { "EEPROM storing 0 failed", "Receive
static void spaceorb_process_packet(struct spaceorb *spaceorb, struct pt_regs *regs) static void spaceorb_process_packet(struct spaceorb *spaceorb, struct pt_regs *regs)
{ {
struct input_dev *dev = &spaceorb->dev; struct input_dev *dev = spaceorb->dev;
unsigned char *data = spaceorb->data; unsigned char *data = spaceorb->data;
unsigned char c = 0; unsigned char c = 0;
int axes[6]; int axes[6];
...@@ -95,8 +93,8 @@ static void spaceorb_process_packet(struct spaceorb *spaceorb, struct pt_regs *r ...@@ -95,8 +93,8 @@ static void spaceorb_process_packet(struct spaceorb *spaceorb, struct pt_regs *r
case 'R': /* Reset packet */ case 'R': /* Reset packet */
spaceorb->data[spaceorb->idx - 1] = 0; spaceorb->data[spaceorb->idx - 1] = 0;
for (i = 1; i < spaceorb->idx && spaceorb->data[i] == ' '; i++); for (i = 1; i < spaceorb->idx && spaceorb->data[i] == ' '; i++);
printk(KERN_INFO "input: %s [%s] on %s\n", printk(KERN_INFO "input: %s [%s] is %s\n",
spaceorb_name, spaceorb->data + i, spaceorb->serio->phys); dev->name, spaceorb->data + i, spaceorb->phys);
break; break;
case 'D': /* Ball + button data */ case 'D': /* Ball + button data */
...@@ -123,7 +121,7 @@ static void spaceorb_process_packet(struct spaceorb *spaceorb, struct pt_regs *r ...@@ -123,7 +121,7 @@ static void spaceorb_process_packet(struct spaceorb *spaceorb, struct pt_regs *r
case 'E': /* Error packet */ case 'E': /* Error packet */
if (spaceorb->idx != 4) return; if (spaceorb->idx != 4) return;
printk(KERN_ERR "joy-spaceorb: Device error. [ "); printk(KERN_ERR "spaceorb: Device error. [ ");
for (i = 0; i < 7; i++) if (data[1] & (1 << i)) printk("%s ", spaceorb_errors[i]); for (i = 0; i < 7; i++) if (data[1] & (1 << i)) printk("%s ", spaceorb_errors[i]);
printk("]\n"); printk("]\n");
break; break;
...@@ -154,9 +152,9 @@ static void spaceorb_disconnect(struct serio *serio) ...@@ -154,9 +152,9 @@ static void spaceorb_disconnect(struct serio *serio)
{ {
struct spaceorb* spaceorb = serio_get_drvdata(serio); struct spaceorb* spaceorb = serio_get_drvdata(serio);
input_unregister_device(&spaceorb->dev);
serio_close(serio); serio_close(serio);
serio_set_drvdata(serio, NULL); serio_set_drvdata(serio, NULL);
input_unregister_device(spaceorb->dev);
kfree(spaceorb); kfree(spaceorb);
} }
...@@ -169,52 +167,48 @@ static void spaceorb_disconnect(struct serio *serio) ...@@ -169,52 +167,48 @@ static void spaceorb_disconnect(struct serio *serio)
static int spaceorb_connect(struct serio *serio, struct serio_driver *drv) static int spaceorb_connect(struct serio *serio, struct serio_driver *drv)
{ {
struct spaceorb *spaceorb; struct spaceorb *spaceorb;
int i, t; struct input_dev *input_dev;
int err; int err = -ENOMEM;
int i;
if (!(spaceorb = kmalloc(sizeof(struct spaceorb), GFP_KERNEL))) spaceorb = kzalloc(sizeof(struct spaceorb), GFP_KERNEL);
return -ENOMEM; input_dev = input_allocate_device();
if (!spaceorb || !input_dev)
goto fail;
memset(spaceorb, 0, sizeof(struct spaceorb)); spaceorb->dev = input_dev;
sprintf(spaceorb->phys, "%s/input0", serio->phys);
spaceorb->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); input_dev->name = "SpaceTec SpaceOrb 360 / Avenger";
input_dev->phys = spaceorb->phys;
input_dev->id.bustype = BUS_RS232;
input_dev->id.vendor = SERIO_SPACEORB;
input_dev->id.product = 0x0001;
input_dev->id.version = 0x0100;
input_dev->cdev.dev = &serio->dev;
input_dev->private = spaceorb;
for (i = 0; i < 6; i++) input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
set_bit(spaceorb_buttons[i], spaceorb->dev.keybit);
for (i = 0; i < 6; i++) {
t = spaceorb_axes[i];
set_bit(t, spaceorb->dev.absbit);
spaceorb->dev.absmin[t] = -508;
spaceorb->dev.absmax[t] = 508;
}
spaceorb->serio = serio; for (i = 0; i < 6; i++)
spaceorb->dev.private = spaceorb; set_bit(spaceorb_buttons[i], input_dev->keybit);
sprintf(spaceorb->phys, "%s/input0", serio->phys);
init_input_dev(&spaceorb->dev); for (i = 0; i < 6; i++)
spaceorb->dev.name = spaceorb_name; input_set_abs_params(input_dev, spaceorb_axes[i], -508, 508, 0, 0);
spaceorb->dev.phys = spaceorb->phys;
spaceorb->dev.id.bustype = BUS_RS232;
spaceorb->dev.id.vendor = SERIO_SPACEORB;
spaceorb->dev.id.product = 0x0001;
spaceorb->dev.id.version = 0x0100;
spaceorb->dev.dev = &serio->dev;
serio_set_drvdata(serio, spaceorb); serio_set_drvdata(serio, spaceorb);
err = serio_open(serio, drv); err = serio_open(serio, drv);
if (err) { if (err)
serio_set_drvdata(serio, NULL); goto fail;
kfree(spaceorb);
return err;
}
input_register_device(&spaceorb->dev);
input_register_device(spaceorb->dev);
return 0; return 0;
fail: serio_set_drvdata(serio, NULL);
input_free_device(input_dev);
kfree(spaceorb);
return err;
} }
/* /*
......
...@@ -48,14 +48,12 @@ MODULE_LICENSE("GPL"); ...@@ -48,14 +48,12 @@ MODULE_LICENSE("GPL");
#define STINGER_MAX_LENGTH 8 #define STINGER_MAX_LENGTH 8
static char *stinger_name = "Gravis Stinger";
/* /*
* Per-Stinger data. * Per-Stinger data.
*/ */
struct stinger { struct stinger {
struct input_dev dev; struct input_dev *dev;
int idx; int idx;
unsigned char data[STINGER_MAX_LENGTH]; unsigned char data[STINGER_MAX_LENGTH];
char phys[32]; char phys[32];
...@@ -68,7 +66,7 @@ struct stinger { ...@@ -68,7 +66,7 @@ struct stinger {
static void stinger_process_packet(struct stinger *stinger, struct pt_regs *regs) static void stinger_process_packet(struct stinger *stinger, struct pt_regs *regs)
{ {
struct input_dev *dev = &stinger->dev; struct input_dev *dev = stinger->dev;
unsigned char *data = stinger->data; unsigned char *data = stinger->data;
if (!stinger->idx) return; if (!stinger->idx) return;
...@@ -126,9 +124,9 @@ static void stinger_disconnect(struct serio *serio) ...@@ -126,9 +124,9 @@ static void stinger_disconnect(struct serio *serio)
{ {
struct stinger *stinger = serio_get_drvdata(serio); struct stinger *stinger = serio_get_drvdata(serio);
input_unregister_device(&stinger->dev);
serio_close(serio); serio_close(serio);
serio_set_drvdata(serio, NULL); serio_set_drvdata(serio, NULL);
input_unregister_device(stinger->dev);
kfree(stinger); kfree(stinger);
} }
...@@ -141,53 +139,46 @@ static void stinger_disconnect(struct serio *serio) ...@@ -141,53 +139,46 @@ static void stinger_disconnect(struct serio *serio)
static int stinger_connect(struct serio *serio, struct serio_driver *drv) static int stinger_connect(struct serio *serio, struct serio_driver *drv)
{ {
struct stinger *stinger; struct stinger *stinger;
int i; struct input_dev *input_dev;
int err; int err = -ENOMEM;
if (!(stinger = kmalloc(sizeof(struct stinger), GFP_KERNEL)))
return -ENOMEM;
memset(stinger, 0, sizeof(struct stinger)); stinger = kmalloc(sizeof(struct stinger), GFP_KERNEL);
input_dev = input_allocate_device();
stinger->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); if (!stinger || !input_dev)
stinger->dev.keybit[LONG(BTN_A)] = BIT(BTN_A) | BIT(BTN_B) | BIT(BTN_C) | BIT(BTN_X) | \ goto fail;
BIT(BTN_Y) | BIT(BTN_Z) | BIT(BTN_TL) | BIT(BTN_TR) | \
BIT(BTN_START) | BIT(BTN_SELECT);
stinger->dev.absbit[0] = BIT(ABS_X) | BIT(ABS_Y);
stinger->dev = input_dev;
sprintf(stinger->phys, "%s/serio0", serio->phys); sprintf(stinger->phys, "%s/serio0", serio->phys);
init_input_dev(&stinger->dev); input_dev->name = "Gravis Stinger";
stinger->dev.name = stinger_name; input_dev->phys = stinger->phys;
stinger->dev.phys = stinger->phys; input_dev->id.bustype = BUS_RS232;
stinger->dev.id.bustype = BUS_RS232; input_dev->id.vendor = SERIO_STINGER;
stinger->dev.id.vendor = SERIO_STINGER; input_dev->id.product = 0x0001;
stinger->dev.id.product = 0x0001; input_dev->id.version = 0x0100;
stinger->dev.id.version = 0x0100; input_dev->cdev.dev = &serio->dev;
stinger->dev.dev = &serio->dev; input_dev->private = stinger;
for (i = 0; i < 2; i++) { input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
stinger->dev.absmax[ABS_X+i] = 64; input_dev->keybit[LONG(BTN_A)] = BIT(BTN_A) | BIT(BTN_B) | BIT(BTN_C) | BIT(BTN_X) |
stinger->dev.absmin[ABS_X+i] = -64; BIT(BTN_Y) | BIT(BTN_Z) | BIT(BTN_TL) | BIT(BTN_TR) |
stinger->dev.absflat[ABS_X+i] = 4; BIT(BTN_START) | BIT(BTN_SELECT);
} input_set_abs_params(input_dev, ABS_X, -64, 64, 0, 4);
input_set_abs_params(input_dev, ABS_Y, -64, 64, 0, 4);
stinger->dev.private = stinger;
serio_set_drvdata(serio, stinger); serio_set_drvdata(serio, stinger);
err = serio_open(serio, drv); err = serio_open(serio, drv);
if (err) { if (err)
serio_set_drvdata(serio, NULL); goto fail;
kfree(stinger);
return err;
}
input_register_device(&stinger->dev);
printk(KERN_INFO "input: %s on %s\n", stinger_name, serio->phys);
input_register_device(stinger->dev);
return 0; return 0;
fail: serio_set_drvdata(serio, NULL);
input_free_device(input_dev);
kfree(stinger);
return err;
} }
/* /*
......
...@@ -63,37 +63,70 @@ MODULE_LICENSE("GPL"); ...@@ -63,37 +63,70 @@ MODULE_LICENSE("GPL");
#define TMDC_ABS_HAT 4 #define TMDC_ABS_HAT 4
#define TMDC_BTN 16 #define TMDC_BTN 16
static unsigned char tmdc_byte_a[16] = { 0, 1, 3, 4, 6, 7 }; static const unsigned char tmdc_byte_a[16] = { 0, 1, 3, 4, 6, 7 };
static unsigned char tmdc_byte_d[16] = { 2, 5, 8, 9 }; static const unsigned char tmdc_byte_d[16] = { 2, 5, 8, 9 };
static signed char tmdc_abs[TMDC_ABS] = static const signed char tmdc_abs[TMDC_ABS] =
{ ABS_X, ABS_Y, ABS_RUDDER, ABS_THROTTLE, ABS_RX, ABS_RY, ABS_RZ }; { ABS_X, ABS_Y, ABS_RUDDER, ABS_THROTTLE, ABS_RX, ABS_RY, ABS_RZ };
static signed char tmdc_abs_hat[TMDC_ABS_HAT] = static const signed char tmdc_abs_hat[TMDC_ABS_HAT] =
{ ABS_HAT0X, ABS_HAT0Y, ABS_HAT1X, ABS_HAT1Y }; { ABS_HAT0X, ABS_HAT0Y, ABS_HAT1X, ABS_HAT1Y };
static signed char tmdc_abs_at[TMDC_ABS] = static const signed char tmdc_abs_at[TMDC_ABS] =
{ ABS_X, ABS_Y, ABS_RUDDER, -1, ABS_THROTTLE }; { ABS_X, ABS_Y, ABS_RUDDER, -1, ABS_THROTTLE };
static signed char tmdc_abs_fm[TMDC_ABS] = static const signed char tmdc_abs_fm[TMDC_ABS] =
{ ABS_RX, ABS_RY, ABS_X, ABS_Y }; { ABS_RX, ABS_RY, ABS_X, ABS_Y };
static short tmdc_btn_pad[TMDC_BTN] = static const short tmdc_btn_pad[TMDC_BTN] =
{ BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_START, BTN_SELECT, BTN_TL, BTN_TR }; { BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_START, BTN_SELECT, BTN_TL, BTN_TR };
static short tmdc_btn_joy[TMDC_BTN] = static const short tmdc_btn_joy[TMDC_BTN] =
{ BTN_TRIGGER, BTN_THUMB, BTN_TOP, BTN_TOP2, BTN_BASE, BTN_BASE2, BTN_THUMB2, BTN_PINKIE, { BTN_TRIGGER, BTN_THUMB, BTN_TOP, BTN_TOP2, BTN_BASE, BTN_BASE2, BTN_THUMB2, BTN_PINKIE,
BTN_BASE3, BTN_BASE4, BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z }; BTN_BASE3, BTN_BASE4, BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z };
static short tmdc_btn_fm[TMDC_BTN] = static const short tmdc_btn_fm[TMDC_BTN] =
{ BTN_TRIGGER, BTN_C, BTN_B, BTN_A, BTN_THUMB, BTN_X, BTN_Y, BTN_Z, BTN_TOP, BTN_TOP2 }; { BTN_TRIGGER, BTN_C, BTN_B, BTN_A, BTN_THUMB, BTN_X, BTN_Y, BTN_Z, BTN_TOP, BTN_TOP2 };
static short tmdc_btn_at[TMDC_BTN] = static const short tmdc_btn_at[TMDC_BTN] =
{ BTN_TRIGGER, BTN_THUMB2, BTN_PINKIE, BTN_THUMB, BTN_BASE6, BTN_BASE5, BTN_BASE4, { BTN_TRIGGER, BTN_THUMB2, BTN_PINKIE, BTN_THUMB, BTN_BASE6, BTN_BASE5, BTN_BASE4,
BTN_BASE3, BTN_BASE2, BTN_BASE }; BTN_BASE3, BTN_BASE2, BTN_BASE };
static struct { static const struct {
int x; int x;
int y; int y;
} tmdc_hat_to_axis[] = {{ 0, 0}, { 1, 0}, { 0,-1}, {-1, 0}, { 0, 1}}; } tmdc_hat_to_axis[] = {{ 0, 0}, { 1, 0}, { 0,-1}, {-1, 0}, { 0, 1}};
static const struct tmdc_model {
unsigned char id;
const char *name;
char abs;
char hats;
char btnc[4];
char btno[4];
const signed char *axes;
const short *buttons;
} tmdc_models[] = {
{ 1, "ThrustMaster Millenium 3D Inceptor", 6, 2, { 4, 2 }, { 4, 6 }, tmdc_abs, tmdc_btn_joy },
{ 3, "ThrustMaster Rage 3D Gamepad", 2, 0, { 8, 2 }, { 0, 0 }, tmdc_abs, tmdc_btn_pad },
{ 4, "ThrustMaster Attack Throttle", 5, 2, { 4, 6 }, { 4, 2 }, tmdc_abs_at, tmdc_btn_at },
{ 8, "ThrustMaster FragMaster", 4, 0, { 8, 2 }, { 0, 0 }, tmdc_abs_fm, tmdc_btn_fm },
{ 163, "Thrustmaster Fusion GamePad", 2, 0, { 8, 2 }, { 0, 0 }, tmdc_abs, tmdc_btn_pad },
{ 0, "Unknown %d-axis, %d-button TM device %d", 0, 0, { 0, 0 }, { 0, 0 }, tmdc_abs, tmdc_btn_joy }
};
struct tmdc_port {
struct input_dev *dev;
char name[64];
char phys[32];
int mode;
const signed char *abs;
const short *btn;
unsigned char absc;
unsigned char btnc[4];
unsigned char btno[4];
};
struct tmdc { struct tmdc {
struct gameport *gameport; struct gameport *gameport;
struct input_dev dev[2]; struct tmdc_port *port[2];
#if 0
struct input_dev *dev[2];
char name[2][64]; char name[2][64];
char phys[2][32]; char phys[2][32];
int mode[2]; int mode[2];
...@@ -102,6 +135,7 @@ struct tmdc { ...@@ -102,6 +135,7 @@ struct tmdc {
unsigned char absc[2]; unsigned char absc[2];
unsigned char btnc[2][4]; unsigned char btnc[2][4];
unsigned char btno[2][4]; unsigned char btno[2][4];
#endif
int reads; int reads;
int bads; int bads;
unsigned char exists; unsigned char exists;
...@@ -156,65 +190,73 @@ static int tmdc_read_packet(struct gameport *gameport, unsigned char data[2][TMD ...@@ -156,65 +190,73 @@ static int tmdc_read_packet(struct gameport *gameport, unsigned char data[2][TMD
return (i[0] == TMDC_MAX_LENGTH) | ((i[1] == TMDC_MAX_LENGTH) << 1); return (i[0] == TMDC_MAX_LENGTH) | ((i[1] == TMDC_MAX_LENGTH) << 1);
} }
/* static int tmdc_parse_packet(struct tmdc_port *port, unsigned char *data)
* tmdc_poll() reads and analyzes ThrustMaster joystick data.
*/
static void tmdc_poll(struct gameport *gameport)
{ {
unsigned char data[2][TMDC_MAX_LENGTH]; int i, k, l;
struct tmdc *tmdc = gameport_get_drvdata(gameport);
struct input_dev *dev;
unsigned char r, bad = 0;
int i, j, k, l;
tmdc->reads++; if (data[TMDC_BYTE_ID] != port->mode)
return -1;
if ((r = tmdc_read_packet(tmdc->gameport, data)) != tmdc->exists)
bad = 1;
else
for (j = 0; j < 2; j++) for (i = 0; i < port->absc; i++) {
if (r & (1 << j) & tmdc->exists) { if (port->abs[i] < 0)
return 0;
if (data[j][TMDC_BYTE_ID] != tmdc->mode[j]) {
bad = 1;
continue;
}
dev = tmdc->dev + j;
for (i = 0; i < tmdc->absc[j]; i++) { input_report_abs(port->dev, port->abs[i], data[tmdc_byte_a[i]]);
if (tmdc->abs[j][i] < 0) continue;
input_report_abs(dev, tmdc->abs[j][i], data[j][tmdc_byte_a[i]]);
} }
switch (tmdc->mode[j]) { switch (port->mode) {
case TMDC_MODE_M3DI: case TMDC_MODE_M3DI:
i = tmdc_byte_d[0]; i = tmdc_byte_d[0];
input_report_abs(dev, ABS_HAT0X, ((data[j][i] >> 3) & 1) - ((data[j][i] >> 1) & 1)); input_report_abs(port->dev, ABS_HAT0X, ((data[i] >> 3) & 1) - ((data[i] >> 1) & 1));
input_report_abs(dev, ABS_HAT0Y, ((data[j][i] >> 2) & 1) - ( data[j][i] & 1)); input_report_abs(port->dev, ABS_HAT0Y, ((data[i] >> 2) & 1) - ( data[i] & 1));
break; break;
case TMDC_MODE_AT: case TMDC_MODE_AT:
i = tmdc_byte_a[3]; i = tmdc_byte_a[3];
input_report_abs(dev, ABS_HAT0X, tmdc_hat_to_axis[(data[j][i] - 141) / 25].x); input_report_abs(port->dev, ABS_HAT0X, tmdc_hat_to_axis[(data[i] - 141) / 25].x);
input_report_abs(dev, ABS_HAT0Y, tmdc_hat_to_axis[(data[j][i] - 141) / 25].y); input_report_abs(port->dev, ABS_HAT0Y, tmdc_hat_to_axis[(data[i] - 141) / 25].y);
break; break;
} }
for (k = l = 0; k < 4; k++) { for (k = l = 0; k < 4; k++) {
for (i = 0; i < tmdc->btnc[j][k]; i++) for (i = 0; i < port->btnc[k]; i++)
input_report_key(dev, tmdc->btn[j][i + l], input_report_key(port->dev, port->btn[i + l],
((data[j][tmdc_byte_d[k]] >> (i + tmdc->btno[j][k])) & 1)); ((data[tmdc_byte_d[k]] >> (i + port->btno[k])) & 1));
l += tmdc->btnc[j][k]; l += port->btnc[k];
} }
input_sync(dev); input_sync(port->dev);
return 0;
}
/*
* tmdc_poll() reads and analyzes ThrustMaster joystick data.
*/
static void tmdc_poll(struct gameport *gameport)
{
unsigned char data[2][TMDC_MAX_LENGTH];
struct tmdc *tmdc = gameport_get_drvdata(gameport);
unsigned char r, bad = 0;
int i;
tmdc->reads++;
if ((r = tmdc_read_packet(tmdc->gameport, data)) != tmdc->exists)
bad = 1;
else {
for (i = 0; i < 2; i++) {
if (r & (1 << i) & tmdc->exists) {
if (tmdc_parse_packet(tmdc->port[i], data[i]))
bad = 1;
}
}
} }
tmdc->bads += bad; tmdc->bads += bad;
...@@ -235,31 +277,89 @@ static void tmdc_close(struct input_dev *dev) ...@@ -235,31 +277,89 @@ static void tmdc_close(struct input_dev *dev)
gameport_stop_polling(tmdc->gameport); gameport_stop_polling(tmdc->gameport);
} }
static int tmdc_setup_port(struct tmdc *tmdc, int idx, unsigned char *data)
{
const struct tmdc_model *model;
struct tmdc_port *port;
struct input_dev *input_dev;
int i, j, b = 0;
tmdc->port[idx] = port = kzalloc(sizeof (struct tmdc_port), GFP_KERNEL);
input_dev = input_allocate_device();
if (!port || !input_dev) {
kfree(port);
input_free_device(input_dev);
return -ENOMEM;
}
port->mode = data[TMDC_BYTE_ID];
for (model = tmdc_models; model->id && model->id != port->mode; model++)
/* empty */;
port->abs = model->axes;
port->btn = model->buttons;
if (!model->id) {
port->absc = data[TMDC_BYTE_DEF] >> 4;
for (i = 0; i < 4; i++)
port->btnc[i] = i < (data[TMDC_BYTE_DEF] & 0xf) ? 8 : 0;
} else {
port->absc = model->abs;
for (i = 0; i < 4; i++)
port->btnc[i] = model->btnc[i];
}
for (i = 0; i < 4; i++)
port->btno[i] = model->btno[i];
snprintf(port->name, sizeof(port->name), model->name,
port->absc, (data[TMDC_BYTE_DEF] & 0xf) << 3, port->mode);
snprintf(port->phys, sizeof(port->phys), "%s/input%d", tmdc->gameport->phys, i);
port->dev = input_dev;
input_dev->name = port->name;
input_dev->phys = port->phys;
input_dev->id.bustype = BUS_GAMEPORT;
input_dev->id.vendor = GAMEPORT_ID_VENDOR_THRUSTMASTER;
input_dev->id.product = model->id;
input_dev->id.version = 0x0100;
input_dev->cdev.dev = &tmdc->gameport->dev;
input_dev->private = tmdc;
input_dev->open = tmdc_open;
input_dev->close = tmdc_close;
input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
for (i = 0; i < port->absc && i < TMDC_ABS; i++)
if (port->abs[i] >= 0)
input_set_abs_params(input_dev, port->abs[i], 8, 248, 2, 4);
for (i = 0; i < model->hats && i < TMDC_ABS_HAT; i++)
input_set_abs_params(input_dev, tmdc_abs_hat[i], -1, 1, 0, 0);
for (i = 0; i < 4; i++) {
for (j = 0; j < port->btnc[i] && j < TMDC_BTN; j++)
set_bit(port->btn[j + b], input_dev->keybit);
b += port->btnc[i];
}
input_register_device(port->dev);
return 0;
}
/* /*
* tmdc_probe() probes for ThrustMaster type joysticks. * tmdc_probe() probes for ThrustMaster type joysticks.
*/ */
static int tmdc_connect(struct gameport *gameport, struct gameport_driver *drv) static int tmdc_connect(struct gameport *gameport, struct gameport_driver *drv)
{ {
static struct models {
unsigned char id;
char *name;
char abs;
char hats;
char btnc[4];
char btno[4];
signed char *axes;
short *buttons;
} models[] = { { 1, "ThrustMaster Millenium 3D Inceptor", 6, 2, { 4, 2 }, { 4, 6 }, tmdc_abs, tmdc_btn_joy },
{ 3, "ThrustMaster Rage 3D Gamepad", 2, 0, { 8, 2 }, { 0, 0 }, tmdc_abs, tmdc_btn_pad },
{ 4, "ThrustMaster Attack Throttle", 5, 2, { 4, 6 }, { 4, 2 }, tmdc_abs_at, tmdc_btn_at },
{ 8, "ThrustMaster FragMaster", 4, 0, { 8, 2 }, { 0, 0 }, tmdc_abs_fm, tmdc_btn_fm },
{ 163, "Thrustmaster Fusion GamePad", 2, 0, { 8, 2 }, { 0, 0 }, tmdc_abs, tmdc_btn_pad },
{ 0, "Unknown %d-axis, %d-button TM device %d", 0, 0, { 0, 0 }, { 0, 0 }, tmdc_abs, tmdc_btn_joy }};
unsigned char data[2][TMDC_MAX_LENGTH]; unsigned char data[2][TMDC_MAX_LENGTH];
struct tmdc *tmdc; struct tmdc *tmdc;
int i, j, k, l, m; int i;
int err; int err;
if (!(tmdc = kzalloc(sizeof(struct tmdc), GFP_KERNEL))) if (!(tmdc = kzalloc(sizeof(struct tmdc), GFP_KERNEL)))
...@@ -281,68 +381,25 @@ static int tmdc_connect(struct gameport *gameport, struct gameport_driver *drv) ...@@ -281,68 +381,25 @@ static int tmdc_connect(struct gameport *gameport, struct gameport_driver *drv)
gameport_set_poll_handler(gameport, tmdc_poll); gameport_set_poll_handler(gameport, tmdc_poll);
gameport_set_poll_interval(gameport, 20); gameport_set_poll_interval(gameport, 20);
for (j = 0; j < 2; j++) for (i = 0; i < 2; i++) {
if (tmdc->exists & (1 << j)) { if (tmdc->exists & (1 << i)) {
tmdc->mode[j] = data[j][TMDC_BYTE_ID]; err = tmdc_setup_port(tmdc, i, data[i]);
if (err)
for (m = 0; models[m].id && models[m].id != tmdc->mode[j]; m++); goto fail3;
tmdc->abs[j] = models[m].axes;
tmdc->btn[j] = models[m].buttons;
if (!models[m].id) {
models[m].abs = data[j][TMDC_BYTE_DEF] >> 4;
for (k = 0; k < 4; k++)
models[m].btnc[k] = k < (data[j][TMDC_BYTE_DEF] & 0xf) ? 8 : 0;
} }
tmdc->absc[j] = models[m].abs;
for (k = 0; k < 4; k++) {
tmdc->btnc[j][k] = models[m].btnc[k];
tmdc->btno[j][k] = models[m].btno[k];
} }
sprintf(tmdc->name[j], models[m].name, models[m].abs, return 0;
(data[j][TMDC_BYTE_DEF] & 0xf) << 3, tmdc->mode[j]);
sprintf(tmdc->phys[j], "%s/input%d", gameport->phys, j);
tmdc->dev[j].private = tmdc;
tmdc->dev[j].open = tmdc_open;
tmdc->dev[j].close = tmdc_close;
tmdc->dev[j].name = tmdc->name[j];
tmdc->dev[j].phys = tmdc->phys[j];
tmdc->dev[j].id.bustype = BUS_GAMEPORT;
tmdc->dev[j].id.vendor = GAMEPORT_ID_VENDOR_THRUSTMASTER;
tmdc->dev[j].id.product = models[m].id;
tmdc->dev[j].id.version = 0x0100;
tmdc->dev[j].evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
for (i = 0; i < models[m].abs && i < TMDC_ABS; i++)
if (tmdc->abs[j][i] >= 0)
input_set_abs_params(&tmdc->dev[j], tmdc->abs[j][i], 8, 248, 2, 4);
for (i = 0; i < models[m].hats && i < TMDC_ABS_HAT; i++)
input_set_abs_params(&tmdc->dev[j], tmdc_abs_hat[i], -1, 1, 0, 0);
for (k = l = 0; k < 4; k++) { fail3: while (--i >= 0) {
for (i = 0; i < models[m].btnc[k] && i < TMDC_BTN; i++) if (tmdc->port[i]) {
set_bit(tmdc->btn[j][i + l], tmdc->dev[j].keybit); input_unregister_device(tmdc->port[i]->dev);
l += models[m].btnc[k]; kfree(tmdc->port[i]);
} }
input_register_device(tmdc->dev + j);
printk(KERN_INFO "input: %s on %s\n", tmdc->name[j], gameport->phys);
} }
fail2: gameport_close(gameport);
return 0; fail1: gameport_set_drvdata(gameport, NULL);
fail2: gameport_close(gameport);
fail1: gameport_set_drvdata(gameport, NULL);
kfree(tmdc); kfree(tmdc);
return err; return err;
} }
...@@ -352,9 +409,12 @@ static void tmdc_disconnect(struct gameport *gameport) ...@@ -352,9 +409,12 @@ static void tmdc_disconnect(struct gameport *gameport)
struct tmdc *tmdc = gameport_get_drvdata(gameport); struct tmdc *tmdc = gameport_get_drvdata(gameport);
int i; int i;
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++) {
if (tmdc->exists & (1 << i)) if (tmdc->port[i]) {
input_unregister_device(tmdc->dev + i); input_unregister_device(tmdc->port[i]->dev);
kfree(tmdc->port[i]);
}
}
gameport_close(gameport); gameport_close(gameport);
gameport_set_drvdata(gameport, NULL); gameport_set_drvdata(gameport, NULL);
kfree(tmdc); kfree(tmdc);
......
...@@ -42,19 +42,21 @@ MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); ...@@ -42,19 +42,21 @@ MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
MODULE_DESCRIPTION("TurboGraFX parallel port interface driver"); MODULE_DESCRIPTION("TurboGraFX parallel port interface driver");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
static int tgfx[] __initdata = { -1, 0, 0, 0, 0, 0, 0, 0 }; #define TGFX_MAX_PORTS 3
static int tgfx_nargs __initdata = 0; #define TGFX_MAX_DEVICES 7
module_param_array_named(map, tgfx, int, &tgfx_nargs, 0);
MODULE_PARM_DESC(map, "Describes first set of devices (<parport#>,<js1>,<js2>,..<js7>");
static int tgfx_2[] __initdata = { -1, 0, 0, 0, 0, 0, 0, 0 }; struct tgfx_config {
static int tgfx_nargs_2 __initdata = 0; int args[TGFX_MAX_DEVICES + 1];
module_param_array_named(map2, tgfx_2, int, &tgfx_nargs_2, 0); int nargs;
MODULE_PARM_DESC(map2, "Describes second set of devices"); };
static int tgfx_3[] __initdata = { -1, 0, 0, 0, 0, 0, 0, 0 }; static struct tgfx_config tgfx[TGFX_MAX_PORTS] __initdata;
static int tgfx_nargs_3 __initdata = 0;
module_param_array_named(map3, tgfx_3, int, &tgfx_nargs_3, 0); module_param_array_named(map, tgfx[0].args, int, &tgfx[0].nargs, 0);
MODULE_PARM_DESC(map, "Describes first set of devices (<parport#>,<js1>,<js2>,..<js7>");
module_param_array_named(map2, tgfx[1].args, int, &tgfx[1].nargs, 0);
MODULE_PARM_DESC(map2, "Describes second set of devices");
module_param_array_named(map3, tgfx[2].args, int, &tgfx[2].nargs, 0);
MODULE_PARM_DESC(map3, "Describes third set of devices"); MODULE_PARM_DESC(map3, "Describes third set of devices");
__obsolete_setup("tgfx="); __obsolete_setup("tgfx=");
...@@ -75,17 +77,17 @@ __obsolete_setup("tgfx_3="); ...@@ -75,17 +77,17 @@ __obsolete_setup("tgfx_3=");
#define TGFX_TOP2 0x08 #define TGFX_TOP2 0x08
static int tgfx_buttons[] = { BTN_TRIGGER, BTN_THUMB, BTN_THUMB2, BTN_TOP, BTN_TOP2 }; static int tgfx_buttons[] = { BTN_TRIGGER, BTN_THUMB, BTN_THUMB2, BTN_TOP, BTN_TOP2 };
static char *tgfx_name = "TurboGraFX Multisystem joystick";
static struct tgfx { static struct tgfx {
struct pardevice *pd; struct pardevice *pd;
struct timer_list timer; struct timer_list timer;
struct input_dev dev[7]; struct input_dev *dev[TGFX_MAX_DEVICES];
char phys[7][32]; char name[TGFX_MAX_DEVICES][64];
char phys[TGFX_MAX_DEVICES][32];
int sticks; int sticks;
int used; int used;
struct semaphore sem; struct semaphore sem;
} *tgfx_base[3]; } *tgfx_base[TGFX_MAX_PORTS];
/* /*
* tgfx_timer() reads and analyzes TurboGraFX joystick data. * tgfx_timer() reads and analyzes TurboGraFX joystick data.
...@@ -100,7 +102,7 @@ static void tgfx_timer(unsigned long private) ...@@ -100,7 +102,7 @@ static void tgfx_timer(unsigned long private)
for (i = 0; i < 7; i++) for (i = 0; i < 7; i++)
if (tgfx->sticks & (1 << i)) { if (tgfx->sticks & (1 << i)) {
dev = tgfx->dev + i; dev = tgfx->dev[i];
parport_write_data(tgfx->pd->port, ~(1 << i)); parport_write_data(tgfx->pd->port, ~(1 << i));
data1 = parport_read_status(tgfx->pd->port) ^ 0x7f; data1 = parport_read_status(tgfx->pd->port) ^ 0x7f;
...@@ -153,118 +155,165 @@ static void tgfx_close(struct input_dev *dev) ...@@ -153,118 +155,165 @@ static void tgfx_close(struct input_dev *dev)
up(&tgfx->sem); up(&tgfx->sem);
} }
/* /*
* tgfx_probe() probes for tg gamepads. * tgfx_probe() probes for tg gamepads.
*/ */
static struct tgfx __init *tgfx_probe(int *config, int nargs) static struct tgfx __init *tgfx_probe(int parport, int *n_buttons, int n_devs)
{ {
struct tgfx *tgfx; struct tgfx *tgfx;
struct input_dev *input_dev;
struct parport *pp; struct parport *pp;
struct pardevice *pd;
int i, j; int i, j;
int err;
if (config[0] < 0) pp = parport_find_number(parport);
return NULL;
if (nargs < 2) {
printk(KERN_ERR "turbografx.c: at least one joystick must be specified\n");
return NULL;
}
pp = parport_find_number(config[0]);
if (!pp) { if (!pp) {
printk(KERN_ERR "turbografx.c: no such parport\n"); printk(KERN_ERR "turbografx.c: no such parport\n");
return NULL; err = -EINVAL;
goto err_out;
} }
if (!(tgfx = kzalloc(sizeof(struct tgfx), GFP_KERNEL))) { pd = parport_register_device(pp, "turbografx", NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL);
parport_put_port(pp); if (!pd) {
return NULL; printk(KERN_ERR "turbografx.c: parport busy already - lp.o loaded?\n");
err = -EBUSY;
goto err_put_pp;
} }
init_MUTEX(&tgfx->sem); tgfx = kzalloc(sizeof(struct tgfx), GFP_KERNEL);
if (!tgfx) {
tgfx->pd = parport_register_device(pp, "turbografx", NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL); printk(KERN_ERR "turbografx.c: Not enough memory\n");
err = -ENOMEM;
parport_put_port(pp); goto err_unreg_pardev;
if (!tgfx->pd) {
printk(KERN_ERR "turbografx.c: parport busy already - lp.o loaded?\n");
kfree(tgfx);
return NULL;
} }
init_MUTEX(&tgfx->sem);
tgfx->pd = pd;
init_timer(&tgfx->timer); init_timer(&tgfx->timer);
tgfx->timer.data = (long) tgfx; tgfx->timer.data = (long) tgfx;
tgfx->timer.function = tgfx_timer; tgfx->timer.function = tgfx_timer;
tgfx->sticks = 0; for (i = 0; i < n_devs; i++) {
if (n_buttons[i] < 1)
for (i = 0; i < nargs - 1; i++) continue;
if (config[i+1] > 0 && config[i+1] < 6) {
tgfx->sticks |= (1 << i); if (n_buttons[i] > 6) {
printk(KERN_ERR "turbografx.c: Invalid number of buttons %d\n", n_buttons[i]);
tgfx->dev[i].private = tgfx; err = -EINVAL;
tgfx->dev[i].open = tgfx_open; goto err_free_devs;
tgfx->dev[i].close = tgfx_close; }
sprintf(tgfx->phys[i], "%s/input0", tgfx->pd->port->name); tgfx->dev[i] = input_dev = input_allocate_device();
if (!input_dev) {
printk(KERN_ERR "turbografx.c: Not enough memory for input device\n");
err = -ENOMEM;
goto err_free_devs;
}
tgfx->dev[i].name = tgfx_name; tgfx->sticks |= (1 << i);
tgfx->dev[i].phys = tgfx->phys[i]; snprintf(tgfx->name[i], sizeof(tgfx->name[i]),
tgfx->dev[i].id.bustype = BUS_PARPORT; "TurboGraFX %d-button Multisystem joystick", n_buttons[i]);
tgfx->dev[i].id.vendor = 0x0003; snprintf(tgfx->phys[i], sizeof(tgfx->phys[i]),
tgfx->dev[i].id.product = config[i+1]; "%s/input%d", tgfx->pd->port->name, i);
tgfx->dev[i].id.version = 0x0100;
input_dev->name = tgfx->name[i];
input_dev->phys = tgfx->phys[i];
input_dev->id.bustype = BUS_PARPORT;
input_dev->id.vendor = 0x0003;
input_dev->id.product = n_buttons[i];
input_dev->id.version = 0x0100;
input_dev->private = tgfx;
input_dev->open = tgfx_open;
input_dev->close = tgfx_close;
input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
input_set_abs_params(input_dev, ABS_X, -1, 1, 0, 0);
input_set_abs_params(input_dev, ABS_Y, -1, 1, 0, 0);
for (j = 0; j < n_buttons[i]; j++)
set_bit(tgfx_buttons[j], input_dev->keybit);
input_register_device(tgfx->dev[i]);
}
tgfx->dev[i].evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); if (!tgfx->sticks) {
tgfx->dev[i].absbit[0] = BIT(ABS_X) | BIT(ABS_Y); printk(KERN_ERR "turbografx.c: No valid devices specified\n");
err = -EINVAL;
goto err_free_tgfx;
}
for (j = 0; j < config[i+1]; j++) return tgfx;
set_bit(tgfx_buttons[j], tgfx->dev[i].keybit);
tgfx->dev[i].absmin[ABS_X] = -1; tgfx->dev[i].absmax[ABS_X] = 1; err_free_devs:
tgfx->dev[i].absmin[ABS_Y] = -1; tgfx->dev[i].absmax[ABS_Y] = 1; while (--i >= 0)
input_unregister_device(tgfx->dev[i]);
err_free_tgfx:
kfree(tgfx);
err_unreg_pardev:
parport_unregister_device(pd);
err_put_pp:
parport_put_port(pp);
err_out:
return ERR_PTR(err);
}
input_register_device(tgfx->dev + i); static void __exit tgfx_remove(struct tgfx *tgfx)
printk(KERN_INFO "input: %d-button Multisystem joystick on %s\n", {
config[i+1], tgfx->pd->port->name); int i;
}
if (!tgfx->sticks) { for (i = 0; i < TGFX_MAX_DEVICES; i++)
if (tgfx->dev[i])
input_unregister_device(tgfx->dev[i]);
parport_unregister_device(tgfx->pd); parport_unregister_device(tgfx->pd);
kfree(tgfx); kfree(tgfx);
return NULL;
}
return tgfx;
} }
static int __init tgfx_init(void) static int __init tgfx_init(void)
{ {
tgfx_base[0] = tgfx_probe(tgfx, tgfx_nargs); int i;
tgfx_base[1] = tgfx_probe(tgfx_2, tgfx_nargs_2); int have_dev = 0;
tgfx_base[2] = tgfx_probe(tgfx_3, tgfx_nargs_3); int err = 0;
if (tgfx_base[0] || tgfx_base[1] || tgfx_base[2]) for (i = 0; i < TGFX_MAX_PORTS; i++) {
return 0; if (tgfx[i].nargs == 0 || tgfx[i].args[0] < 0)
continue;
if (tgfx[i].nargs < 2) {
printk(KERN_ERR "turbografx.c: at least one joystick must be specified\n");
err = -EINVAL;
break;
}
tgfx_base[i] = tgfx_probe(tgfx[i].args[0], tgfx[i].args + 1, tgfx[i].nargs - 1);
if (IS_ERR(tgfx_base[i])) {
err = PTR_ERR(tgfx_base[i]);
break;
}
return -ENODEV; have_dev = 1;
}
if (err) {
while (--i >= 0)
tgfx_remove(tgfx_base[i]);
return err;
}
return have_dev ? 0 : -ENODEV;
} }
static void __exit tgfx_exit(void) static void __exit tgfx_exit(void)
{ {
int i, j; int i;
for (i = 0; i < 3; i++) for (i = 0; i < TGFX_MAX_PORTS; i++)
if (tgfx_base[i]) { if (tgfx_base[i])
for (j = 0; j < 7; j++) tgfx_remove(tgfx_base[i]);
if (tgfx_base[i]->sticks & (1 << j))
input_unregister_device(tgfx_base[i]->dev + j);
parport_unregister_device(tgfx_base[i]->pd);
}
} }
module_init(tgfx_init); module_init(tgfx_init);
......
...@@ -69,8 +69,6 @@ MODULE_LICENSE("GPL"); ...@@ -69,8 +69,6 @@ MODULE_LICENSE("GPL");
#define TWIDJOY_MAX_LENGTH 5 #define TWIDJOY_MAX_LENGTH 5
static char *twidjoy_name = "Handykey Twiddler";
static struct twidjoy_button_spec { static struct twidjoy_button_spec {
int bitshift; int bitshift;
int bitmask; int bitmask;
...@@ -95,7 +93,7 @@ twidjoy_buttons[] = { ...@@ -95,7 +93,7 @@ twidjoy_buttons[] = {
*/ */
struct twidjoy { struct twidjoy {
struct input_dev dev; struct input_dev *dev;
int idx; int idx;
unsigned char data[TWIDJOY_MAX_LENGTH]; unsigned char data[TWIDJOY_MAX_LENGTH];
char phys[32]; char phys[32];
...@@ -108,8 +106,7 @@ struct twidjoy { ...@@ -108,8 +106,7 @@ struct twidjoy {
static void twidjoy_process_packet(struct twidjoy *twidjoy, struct pt_regs *regs) static void twidjoy_process_packet(struct twidjoy *twidjoy, struct pt_regs *regs)
{ {
if (twidjoy->idx == TWIDJOY_MAX_LENGTH) { struct input_dev *dev = twidjoy->dev;
struct input_dev *dev = &twidjoy->dev;
unsigned char *data = twidjoy->data; unsigned char *data = twidjoy->data;
struct twidjoy_button_spec *bp; struct twidjoy_button_spec *bp;
int button_bits, abs_x, abs_y; int button_bits, abs_x, abs_y;
...@@ -136,9 +133,6 @@ static void twidjoy_process_packet(struct twidjoy *twidjoy, struct pt_regs *regs ...@@ -136,9 +133,6 @@ static void twidjoy_process_packet(struct twidjoy *twidjoy, struct pt_regs *regs
input_report_abs(dev, ABS_Y, +abs_y); input_report_abs(dev, ABS_Y, +abs_y);
input_sync(dev); input_sync(dev);
}
return;
} }
/* /*
...@@ -179,9 +173,9 @@ static void twidjoy_disconnect(struct serio *serio) ...@@ -179,9 +173,9 @@ static void twidjoy_disconnect(struct serio *serio)
{ {
struct twidjoy *twidjoy = serio_get_drvdata(serio); struct twidjoy *twidjoy = serio_get_drvdata(serio);
input_unregister_device(&twidjoy->dev);
serio_close(serio); serio_close(serio);
serio_set_drvdata(serio, NULL); serio_set_drvdata(serio, NULL);
input_unregister_device(twidjoy->dev);
kfree(twidjoy); kfree(twidjoy);
} }
...@@ -195,59 +189,49 @@ static int twidjoy_connect(struct serio *serio, struct serio_driver *drv) ...@@ -195,59 +189,49 @@ static int twidjoy_connect(struct serio *serio, struct serio_driver *drv)
{ {
struct twidjoy_button_spec *bp; struct twidjoy_button_spec *bp;
struct twidjoy *twidjoy; struct twidjoy *twidjoy;
struct input_dev *input_dev;
int err = -ENOMEM;
int i; int i;
int err;
if (!(twidjoy = kmalloc(sizeof(struct twidjoy), GFP_KERNEL)))
return -ENOMEM;
memset(twidjoy, 0, sizeof(struct twidjoy)); twidjoy = kzalloc(sizeof(struct twidjoy), GFP_KERNEL);
input_dev = input_allocate_device();
if (!twidjoy || !input_dev)
goto fail;
twidjoy->dev = input_dev;
sprintf(twidjoy->phys, "%s/input0", serio->phys); sprintf(twidjoy->phys, "%s/input0", serio->phys);
init_input_dev(&twidjoy->dev); input_dev->name = "Handykey Twiddler";
twidjoy->dev.name = twidjoy_name; input_dev->phys = twidjoy->phys;
twidjoy->dev.phys = twidjoy->phys; input_dev->id.bustype = BUS_RS232;
twidjoy->dev.id.bustype = BUS_RS232; input_dev->id.vendor = SERIO_TWIDJOY;
twidjoy->dev.id.vendor = SERIO_TWIDJOY; input_dev->id.product = 0x0001;
twidjoy->dev.id.product = 0x0001; input_dev->id.version = 0x0100;
twidjoy->dev.id.version = 0x0100; input_dev->cdev.dev = &serio->dev;
twidjoy->dev.dev = &serio->dev; input_dev->private = twidjoy;
twidjoy->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
input_dev->absbit[0] = BIT(ABS_X) | BIT(ABS_Y);
for (bp = twidjoy_buttons; bp->bitmask; bp++) { 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++) for (i = 0; i < bp->bitmask; i++)
set_bit(bp->buttons[i], twidjoy->dev.keybit); set_bit(bp->buttons[i], input_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;
serio_set_drvdata(serio, twidjoy); serio_set_drvdata(serio, twidjoy);
err = serio_open(serio, drv); err = serio_open(serio, drv);
if (err) { if (err)
serio_set_drvdata(serio, NULL); goto fail;
kfree(twidjoy);
return err;
}
input_register_device(&twidjoy->dev);
printk(KERN_INFO "input: %s on %s\n", twidjoy_name, serio->phys);
input_register_device(twidjoy->dev);
return 0; return 0;
fail: serio_set_drvdata(serio, NULL);
input_free_device(input_dev);
kfree(twidjoy);
return err;
} }
/* /*
......
...@@ -47,14 +47,13 @@ MODULE_LICENSE("GPL"); ...@@ -47,14 +47,13 @@ MODULE_LICENSE("GPL");
#define WARRIOR_MAX_LENGTH 16 #define WARRIOR_MAX_LENGTH 16
static char warrior_lengths[] = { 0, 4, 12, 3, 4, 4, 0, 0 }; static char warrior_lengths[] = { 0, 4, 12, 3, 4, 4, 0, 0 };
static char *warrior_name = "Logitech WingMan Warrior";
/* /*
* Per-Warrior data. * Per-Warrior data.
*/ */
struct warrior { struct warrior {
struct input_dev dev; struct input_dev *dev;
int idx, len; int idx, len;
unsigned char data[WARRIOR_MAX_LENGTH]; unsigned char data[WARRIOR_MAX_LENGTH];
char phys[32]; char phys[32];
...@@ -67,7 +66,7 @@ struct warrior { ...@@ -67,7 +66,7 @@ struct warrior {
static void warrior_process_packet(struct warrior *warrior, struct pt_regs *regs) static void warrior_process_packet(struct warrior *warrior, struct pt_regs *regs)
{ {
struct input_dev *dev = &warrior->dev; struct input_dev *dev = warrior->dev;
unsigned char *data = warrior->data; unsigned char *data = warrior->data;
if (!warrior->idx) return; if (!warrior->idx) return;
...@@ -131,9 +130,9 @@ static void warrior_disconnect(struct serio *serio) ...@@ -131,9 +130,9 @@ static void warrior_disconnect(struct serio *serio)
{ {
struct warrior *warrior = serio_get_drvdata(serio); struct warrior *warrior = serio_get_drvdata(serio);
input_unregister_device(&warrior->dev);
serio_close(serio); serio_close(serio);
serio_set_drvdata(serio, NULL); serio_set_drvdata(serio, NULL);
input_unregister_device(warrior->dev);
kfree(warrior); kfree(warrior);
} }
...@@ -146,60 +145,48 @@ static void warrior_disconnect(struct serio *serio) ...@@ -146,60 +145,48 @@ static void warrior_disconnect(struct serio *serio)
static int warrior_connect(struct serio *serio, struct serio_driver *drv) static int warrior_connect(struct serio *serio, struct serio_driver *drv)
{ {
struct warrior *warrior; struct warrior *warrior;
int i; struct input_dev *input_dev;
int err; int err = -ENOMEM;
if (!(warrior = kmalloc(sizeof(struct warrior), GFP_KERNEL))) warrior = kzalloc(sizeof(struct warrior), GFP_KERNEL);
return -ENOMEM; input_dev = input_allocate_device();
if (!warrior || !input_dev)
memset(warrior, 0, sizeof(struct warrior)); goto fail;
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);
warrior->dev = input_dev;
sprintf(warrior->phys, "%s/input0", serio->phys); sprintf(warrior->phys, "%s/input0", serio->phys);
init_input_dev(&warrior->dev); input_dev->name = "Logitech WingMan Warrior";
warrior->dev.name = warrior_name; input_dev->phys = warrior->phys;
warrior->dev.phys = warrior->phys; input_dev->id.bustype = BUS_RS232;
warrior->dev.id.bustype = BUS_RS232; input_dev->id.vendor = SERIO_WARRIOR;
warrior->dev.id.vendor = SERIO_WARRIOR; input_dev->id.product = 0x0001;
warrior->dev.id.product = 0x0001; input_dev->id.version = 0x0100;
warrior->dev.id.version = 0x0100; input_dev->cdev.dev = &serio->dev;
warrior->dev.dev = &serio->dev; input_dev->private = warrior;
for (i = 0; i < 2; i++) { input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL) | BIT(EV_ABS);
warrior->dev.absmax[ABS_X+i] = -64; input_dev->keybit[LONG(BTN_TRIGGER)] = BIT(BTN_TRIGGER) | BIT(BTN_THUMB) | BIT(BTN_TOP) | BIT(BTN_TOP2);
warrior->dev.absmin[ABS_X+i] = 64; input_dev->relbit[0] = BIT(REL_DIAL);
warrior->dev.absflat[ABS_X+i] = 8; 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);
warrior->dev.absmax[ABS_THROTTLE] = -112; input_set_abs_params(input_dev, ABS_HAT0X, -1, 1, 0, 0);
warrior->dev.absmin[ABS_THROTTLE] = 112; input_set_abs_params(input_dev, ABS_HAT0X, -1, 1, 0, 0);
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_set_drvdata(serio, warrior); serio_set_drvdata(serio, warrior);
err = serio_open(serio, drv); err = serio_open(serio, drv);
if (err) { if (err)
serio_set_drvdata(serio, NULL); goto fail;
kfree(warrior);
return err;
}
input_register_device(&warrior->dev);
printk(KERN_INFO "input: Logitech WingMan Warrior on %s\n", serio->phys);
input_register_device(warrior->dev);
return 0; return 0;
fail: serio_set_drvdata(serio, NULL);
input_free_device(input_dev);
kfree(warrior);
return err;
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment