aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/joystick
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/input/joystick')
-rw-r--r--drivers/input/joystick/a3d.c88
-rw-r--r--drivers/input/joystick/db9.c85
-rw-r--r--drivers/input/joystick/gamecon.c361
-rw-r--r--drivers/input/joystick/grip.c11
-rw-r--r--drivers/input/joystick/iforce/iforce-main.c2
-rw-r--r--drivers/input/joystick/iforce/iforce-packets.c4
-rw-r--r--drivers/input/joystick/iforce/iforce-usb.c1
-rw-r--r--drivers/input/joystick/sidewinder.c10
-rw-r--r--drivers/input/joystick/tmdc.c15
-rw-r--r--drivers/input/joystick/turbografx.c20
-rw-r--r--drivers/input/joystick/twidjoy.c4
11 files changed, 343 insertions, 258 deletions
diff --git a/drivers/input/joystick/a3d.c b/drivers/input/joystick/a3d.c
index 4571ea3a4b92..4612d13ea756 100644
--- a/drivers/input/joystick/a3d.c
+++ b/drivers/input/joystick/a3d.c
@@ -57,7 +57,7 @@ static char *a3d_names[] = { NULL, "FP-Gaming Assassin 3D", "MadCatz Panther", "
57struct a3d { 57struct a3d {
58 struct gameport *gameport; 58 struct gameport *gameport;
59 struct gameport *adc; 59 struct gameport *adc;
60 struct input_dev dev; 60 struct input_dev *dev;
61 int axes[4]; 61 int axes[4];
62 int buttons; 62 int buttons;
63 int mode; 63 int mode;
@@ -115,7 +115,7 @@ static int a3d_csum(char *data, int count)
115 115
116static void a3d_read(struct a3d *a3d, unsigned char *data) 116static void a3d_read(struct a3d *a3d, unsigned char *data)
117{ 117{
118 struct input_dev *dev = &a3d->dev; 118 struct input_dev *dev = a3d->dev;
119 119
120 switch (a3d->mode) { 120 switch (a3d->mode) {
121 121
@@ -265,14 +265,20 @@ static void a3d_close(struct input_dev *dev)
265static int a3d_connect(struct gameport *gameport, struct gameport_driver *drv) 265static int a3d_connect(struct gameport *gameport, struct gameport_driver *drv)
266{ 266{
267 struct a3d *a3d; 267 struct a3d *a3d;
268 struct input_dev *input_dev;
268 struct gameport *adc; 269 struct gameport *adc;
269 unsigned char data[A3D_MAX_LENGTH]; 270 unsigned char data[A3D_MAX_LENGTH];
270 int i; 271 int i;
271 int err; 272 int err;
272 273
273 if (!(a3d = kzalloc(sizeof(struct a3d), GFP_KERNEL))) 274 a3d = kzalloc(sizeof(struct a3d), GFP_KERNEL);
274 return -ENOMEM; 275 input_dev = input_allocate_device();
276 if (!a3d || !input_dev) {
277 err = -ENOMEM;
278 goto fail1;
279 }
275 280
281 a3d->dev = input_dev;
276 a3d->gameport = gameport; 282 a3d->gameport = gameport;
277 283
278 gameport_set_drvdata(gameport, a3d); 284 gameport_set_drvdata(gameport, a3d);
@@ -302,42 +308,48 @@ static int a3d_connect(struct gameport *gameport, struct gameport_driver *drv)
302 308
303 sprintf(a3d->phys, "%s/input0", gameport->phys); 309 sprintf(a3d->phys, "%s/input0", gameport->phys);
304 310
311 input_dev->name = a3d_names[a3d->mode];
312 input_dev->phys = a3d->phys;
313 input_dev->id.bustype = BUS_GAMEPORT;
314 input_dev->id.vendor = GAMEPORT_ID_VENDOR_MADCATZ;
315 input_dev->id.product = a3d->mode;
316 input_dev->id.version = 0x0100;
317 input_dev->cdev.dev = &gameport->dev;
318 input_dev->private = a3d;
319 input_dev->open = a3d_open;
320 input_dev->close = a3d_close;
321
305 if (a3d->mode == A3D_MODE_PXL) { 322 if (a3d->mode == A3D_MODE_PXL) {
306 323
307 int axes[] = { ABS_X, ABS_Y, ABS_THROTTLE, ABS_RUDDER }; 324 int axes[] = { ABS_X, ABS_Y, ABS_THROTTLE, ABS_RUDDER };
308 325
309 a3d->length = 33; 326 a3d->length = 33;
310 327
311 init_input_dev(&a3d->dev); 328 input_dev->evbit[0] |= BIT(EV_ABS) | BIT(EV_KEY) | BIT(EV_REL);
312 329 input_dev->relbit[0] |= BIT(REL_X) | BIT(REL_Y);
313 a3d->dev.evbit[0] |= BIT(EV_ABS) | BIT(EV_KEY) | BIT(EV_REL); 330 input_dev->absbit[0] |= BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_THROTTLE) | BIT(ABS_RUDDER)
314 a3d->dev.relbit[0] |= BIT(REL_X) | BIT(REL_Y); 331 | BIT(ABS_HAT0X) | BIT(ABS_HAT0Y) | BIT(ABS_HAT1X) | BIT(ABS_HAT1Y);
315 a3d->dev.absbit[0] |= BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_THROTTLE) | BIT(ABS_RUDDER) 332 input_dev->keybit[LONG(BTN_MOUSE)] |= BIT(BTN_RIGHT) | BIT(BTN_LEFT) | BIT(BTN_MIDDLE)
316 | BIT(ABS_HAT0X) | BIT(ABS_HAT0Y) | BIT(ABS_HAT1X) | BIT(ABS_HAT1Y); 333 | BIT(BTN_SIDE) | BIT(BTN_EXTRA);
317 334 input_dev->keybit[LONG(BTN_JOYSTICK)] |= BIT(BTN_TRIGGER) | BIT(BTN_THUMB) | BIT(BTN_TOP)
318 a3d->dev.keybit[LONG(BTN_MOUSE)] |= BIT(BTN_RIGHT) | BIT(BTN_LEFT) | BIT(BTN_MIDDLE) 335 | BIT(BTN_PINKIE);
319 | BIT(BTN_SIDE) | BIT(BTN_EXTRA);
320
321 a3d->dev.keybit[LONG(BTN_JOYSTICK)] |= BIT(BTN_TRIGGER) | BIT(BTN_THUMB) | BIT(BTN_TOP) | BIT(BTN_PINKIE);
322 336
323 a3d_read(a3d, data); 337 a3d_read(a3d, data);
324 338
325 for (i = 0; i < 4; i++) { 339 for (i = 0; i < 4; i++) {
326 if (i < 2) 340 if (i < 2)
327 input_set_abs_params(&a3d->dev, axes[i], 48, a3d->dev.abs[axes[i]] * 2 - 48, 0, 8); 341 input_set_abs_params(input_dev, axes[i], 48, input_dev->abs[axes[i]] * 2 - 48, 0, 8);
328 else 342 else
329 input_set_abs_params(&a3d->dev, axes[i], 2, 253, 0, 0); 343 input_set_abs_params(input_dev, axes[i], 2, 253, 0, 0);
330 input_set_abs_params(&a3d->dev, ABS_HAT0X + i, -1, 1, 0, 0); 344 input_set_abs_params(input_dev, ABS_HAT0X + i, -1, 1, 0, 0);
331 } 345 }
332 346
333 } else { 347 } else {
334 a3d->length = 29; 348 a3d->length = 29;
335 349
336 init_input_dev(&a3d->dev); 350 input_dev->evbit[0] |= BIT(EV_KEY) | BIT(EV_REL);
337 351 input_dev->relbit[0] |= BIT(REL_X) | BIT(REL_Y);
338 a3d->dev.evbit[0] |= BIT(EV_KEY) | BIT(EV_REL); 352 input_dev->keybit[LONG(BTN_MOUSE)] |= BIT(BTN_RIGHT) | BIT(BTN_LEFT) | BIT(BTN_MIDDLE);
339 a3d->dev.relbit[0] |= BIT(REL_X) | BIT(REL_Y);
340 a3d->dev.keybit[LONG(BTN_MOUSE)] |= BIT(BTN_RIGHT) | BIT(BTN_LEFT) | BIT(BTN_MIDDLE);
341 353
342 a3d_read(a3d, data); 354 a3d_read(a3d, data);
343 355
@@ -358,24 +370,17 @@ static int a3d_connect(struct gameport *gameport, struct gameport_driver *drv)
358 } 370 }
359 } 371 }
360 372
361 a3d->dev.private = a3d; 373 err = input_register_device(a3d->dev);
362 a3d->dev.open = a3d_open; 374 if (err)
363 a3d->dev.close = a3d_close; 375 goto fail3;
364
365 a3d->dev.name = a3d_names[a3d->mode];
366 a3d->dev.phys = a3d->phys;
367 a3d->dev.id.bustype = BUS_GAMEPORT;
368 a3d->dev.id.vendor = GAMEPORT_ID_VENDOR_MADCATZ;
369 a3d->dev.id.product = a3d->mode;
370 a3d->dev.id.version = 0x0100;
371
372 input_register_device(&a3d->dev);
373 printk(KERN_INFO "input: %s on %s\n", a3d_names[a3d->mode], a3d->phys);
374 376
375 return 0; 377 return 0;
376 378
377fail2: gameport_close(gameport); 379 fail3: if (a3d->adc)
378fail1: gameport_set_drvdata(gameport, NULL); 380 gameport_unregister_port(a3d->adc);
381 fail2: gameport_close(gameport);
382 fail1: gameport_set_drvdata(gameport, NULL);
383 input_free_device(input_dev);
379 kfree(a3d); 384 kfree(a3d);
380 return err; 385 return err;
381} 386}
@@ -384,11 +389,9 @@ static void a3d_disconnect(struct gameport *gameport)
384{ 389{
385 struct a3d *a3d = gameport_get_drvdata(gameport); 390 struct a3d *a3d = gameport_get_drvdata(gameport);
386 391
387 input_unregister_device(&a3d->dev); 392 input_unregister_device(a3d->dev);
388 if (a3d->adc) { 393 if (a3d->adc)
389 gameport_unregister_port(a3d->adc); 394 gameport_unregister_port(a3d->adc);
390 a3d->adc = NULL;
391 }
392 gameport_close(gameport); 395 gameport_close(gameport);
393 gameport_set_drvdata(gameport, NULL); 396 gameport_set_drvdata(gameport, NULL);
394 kfree(a3d); 397 kfree(a3d);
@@ -397,6 +400,7 @@ static void a3d_disconnect(struct gameport *gameport)
397static struct gameport_driver a3d_drv = { 400static struct gameport_driver a3d_drv = {
398 .driver = { 401 .driver = {
399 .name = "adc", 402 .name = "adc",
403 .owner = THIS_MODULE,
400 }, 404 },
401 .description = DRIVER_DESC, 405 .description = DRIVER_DESC,
402 .connect = a3d_connect, 406 .connect = a3d_connect,
diff --git a/drivers/input/joystick/db9.c b/drivers/input/joystick/db9.c
index 499344c72756..dcffc34f30c3 100644
--- a/drivers/input/joystick/db9.c
+++ b/drivers/input/joystick/db9.c
@@ -275,68 +275,70 @@ static unsigned char db9_saturn_read_packet(struct parport *port, unsigned char
275/* 275/*
276 * db9_saturn_report() analyzes packet and reports. 276 * db9_saturn_report() analyzes packet and reports.
277 */ 277 */
278static int db9_saturn_report(unsigned char id, unsigned char data[60], struct input_dev *dev, int n, int max_pads) 278static int db9_saturn_report(unsigned char id, unsigned char data[60], struct input_dev *devs[], int n, int max_pads)
279{ 279{
280 struct input_dev *dev;
280 int tmp, i, j; 281 int tmp, i, j;
281 282
282 tmp = (id == 0x41) ? 60 : 10; 283 tmp = (id == 0x41) ? 60 : 10;
283 for (j = 0; (j < tmp) && (n < max_pads); j += 10, n++) { 284 for (j = 0; j < tmp && n < max_pads; j += 10, n++) {
285 dev = devs[n];
284 switch (data[j]) { 286 switch (data[j]) {
285 case 0x16: /* multi controller (analog 4 axis) */ 287 case 0x16: /* multi controller (analog 4 axis) */
286 input_report_abs(dev + n, db9_abs[5], data[j + 6]); 288 input_report_abs(dev, db9_abs[5], data[j + 6]);
287 case 0x15: /* mission stick (analog 3 axis) */ 289 case 0x15: /* mission stick (analog 3 axis) */
288 input_report_abs(dev + n, db9_abs[3], data[j + 4]); 290 input_report_abs(dev, db9_abs[3], data[j + 4]);
289 input_report_abs(dev + n, db9_abs[4], data[j + 5]); 291 input_report_abs(dev, db9_abs[4], data[j + 5]);
290 case 0x13: /* racing controller (analog 1 axis) */ 292 case 0x13: /* racing controller (analog 1 axis) */
291 input_report_abs(dev + n, db9_abs[2], data[j + 3]); 293 input_report_abs(dev, db9_abs[2], data[j + 3]);
292 case 0x34: /* saturn keyboard (udlr ZXC ASD QE Esc) */ 294 case 0x34: /* saturn keyboard (udlr ZXC ASD QE Esc) */
293 case 0x02: /* digital pad (digital 2 axis + buttons) */ 295 case 0x02: /* digital pad (digital 2 axis + buttons) */
294 input_report_abs(dev + n, db9_abs[0], !(data[j + 1] & 128) - !(data[j + 1] & 64)); 296 input_report_abs(dev, db9_abs[0], !(data[j + 1] & 128) - !(data[j + 1] & 64));
295 input_report_abs(dev + n, db9_abs[1], !(data[j + 1] & 32) - !(data[j + 1] & 16)); 297 input_report_abs(dev, db9_abs[1], !(data[j + 1] & 32) - !(data[j + 1] & 16));
296 for (i = 0; i < 9; i++) 298 for (i = 0; i < 9; i++)
297 input_report_key(dev + n, db9_cd32_btn[i], ~data[j + db9_saturn_byte[i]] & db9_saturn_mask[i]); 299 input_report_key(dev, db9_cd32_btn[i], ~data[j + db9_saturn_byte[i]] & db9_saturn_mask[i]);
298 break; 300 break;
299 case 0x19: /* mission stick x2 (analog 6 axis + buttons) */ 301 case 0x19: /* mission stick x2 (analog 6 axis + buttons) */
300 input_report_abs(dev + n, db9_abs[0], !(data[j + 1] & 128) - !(data[j + 1] & 64)); 302 input_report_abs(dev, db9_abs[0], !(data[j + 1] & 128) - !(data[j + 1] & 64));
301 input_report_abs(dev + n, db9_abs[1], !(data[j + 1] & 32) - !(data[j + 1] & 16)); 303 input_report_abs(dev, db9_abs[1], !(data[j + 1] & 32) - !(data[j + 1] & 16));
302 for (i = 0; i < 9; i++) 304 for (i = 0; i < 9; i++)
303 input_report_key(dev + n, db9_cd32_btn[i], ~data[j + db9_saturn_byte[i]] & db9_saturn_mask[i]); 305 input_report_key(dev, db9_cd32_btn[i], ~data[j + db9_saturn_byte[i]] & db9_saturn_mask[i]);
304 input_report_abs(dev + n, db9_abs[2], data[j + 3]); 306 input_report_abs(dev, db9_abs[2], data[j + 3]);
305 input_report_abs(dev + n, db9_abs[3], data[j + 4]); 307 input_report_abs(dev, db9_abs[3], data[j + 4]);
306 input_report_abs(dev + n, db9_abs[4], data[j + 5]); 308 input_report_abs(dev, db9_abs[4], data[j + 5]);
307 /* 309 /*
308 input_report_abs(dev + n, db9_abs[8], (data[j + 6] & 128 ? 0 : 1) - (data[j + 6] & 64 ? 0 : 1)); 310 input_report_abs(dev, db9_abs[8], (data[j + 6] & 128 ? 0 : 1) - (data[j + 6] & 64 ? 0 : 1));
309 input_report_abs(dev + n, db9_abs[9], (data[j + 6] & 32 ? 0 : 1) - (data[j + 6] & 16 ? 0 : 1)); 311 input_report_abs(dev, db9_abs[9], (data[j + 6] & 32 ? 0 : 1) - (data[j + 6] & 16 ? 0 : 1));
310 */ 312 */
311 input_report_abs(dev + n, db9_abs[6], data[j + 7]); 313 input_report_abs(dev, db9_abs[6], data[j + 7]);
312 input_report_abs(dev + n, db9_abs[7], data[j + 8]); 314 input_report_abs(dev, db9_abs[7], data[j + 8]);
313 input_report_abs(dev + n, db9_abs[5], data[j + 9]); 315 input_report_abs(dev, db9_abs[5], data[j + 9]);
314 break; 316 break;
315 case 0xd3: /* sankyo ff (analog 1 axis + stop btn) */ 317 case 0xd3: /* sankyo ff (analog 1 axis + stop btn) */
316 input_report_key(dev + n, BTN_A, data[j + 3] & 0x80); 318 input_report_key(dev, BTN_A, data[j + 3] & 0x80);
317 input_report_abs(dev + n, db9_abs[2], data[j + 3] & 0x7f); 319 input_report_abs(dev, db9_abs[2], data[j + 3] & 0x7f);
318 break; 320 break;
319 case 0xe3: /* shuttle mouse (analog 2 axis + buttons. signed value) */ 321 case 0xe3: /* shuttle mouse (analog 2 axis + buttons. signed value) */
320 input_report_key(dev + n, BTN_START, data[j + 1] & 0x08); 322 input_report_key(dev, BTN_START, data[j + 1] & 0x08);
321 input_report_key(dev + n, BTN_A, data[j + 1] & 0x04); 323 input_report_key(dev, BTN_A, data[j + 1] & 0x04);
322 input_report_key(dev + n, BTN_C, data[j + 1] & 0x02); 324 input_report_key(dev, BTN_C, data[j + 1] & 0x02);
323 input_report_key(dev + n, BTN_B, data[j + 1] & 0x01); 325 input_report_key(dev, BTN_B, data[j + 1] & 0x01);
324 input_report_abs(dev + n, db9_abs[2], data[j + 2] ^ 0x80); 326 input_report_abs(dev, db9_abs[2], data[j + 2] ^ 0x80);
325 input_report_abs(dev + n, db9_abs[3], (0xff-(data[j + 3] ^ 0x80))+1); /* */ 327 input_report_abs(dev, db9_abs[3], (0xff-(data[j + 3] ^ 0x80))+1); /* */
326 break; 328 break;
327 case 0xff: 329 case 0xff:
328 default: /* no pad */ 330 default: /* no pad */
329 input_report_abs(dev + n, db9_abs[0], 0); 331 input_report_abs(dev, db9_abs[0], 0);
330 input_report_abs(dev + n, db9_abs[1], 0); 332 input_report_abs(dev, db9_abs[1], 0);
331 for (i = 0; i < 9; i++) 333 for (i = 0; i < 9; i++)
332 input_report_key(dev + n, db9_cd32_btn[i], 0); 334 input_report_key(dev, db9_cd32_btn[i], 0);
333 break; 335 break;
334 } 336 }
335 } 337 }
336 return n; 338 return n;
337} 339}
338 340
339static int db9_saturn(int mode, struct parport *port, struct input_dev *dev) 341static int db9_saturn(int mode, struct parport *port, struct input_dev *devs[])
340{ 342{
341 unsigned char id, data[60]; 343 unsigned char id, data[60];
342 int type, n, max_pads; 344 int type, n, max_pads;
@@ -361,7 +363,7 @@ static int db9_saturn(int mode, struct parport *port, struct input_dev *dev)
361 max_pads = min(db9_modes[mode].n_pads, DB9_MAX_DEVICES); 363 max_pads = min(db9_modes[mode].n_pads, DB9_MAX_DEVICES);
362 for (tmp = 0, i = 0; i < n; i++) { 364 for (tmp = 0, i = 0; i < n; i++) {
363 id = db9_saturn_read_packet(port, data, type + i, 1); 365 id = db9_saturn_read_packet(port, data, type + i, 1);
364 tmp = db9_saturn_report(id, data, dev, tmp, max_pads); 366 tmp = db9_saturn_report(id, data, devs, tmp, max_pads);
365 } 367 }
366 return 0; 368 return 0;
367} 369}
@@ -489,7 +491,7 @@ static void db9_timer(unsigned long private)
489 case DB9_SATURN_DPP: 491 case DB9_SATURN_DPP:
490 case DB9_SATURN_DPP_2: 492 case DB9_SATURN_DPP_2:
491 493
492 db9_saturn(db9->mode, port, dev); 494 db9_saturn(db9->mode, port, db9->dev);
493 break; 495 break;
494 496
495 case DB9_CD32_PAD: 497 case DB9_CD32_PAD:
@@ -614,7 +616,7 @@ static struct db9 __init *db9_probe(int parport, int mode)
614 if (!input_dev) { 616 if (!input_dev) {
615 printk(KERN_ERR "db9.c: Not enough memory for input device\n"); 617 printk(KERN_ERR "db9.c: Not enough memory for input device\n");
616 err = -ENOMEM; 618 err = -ENOMEM;
617 goto err_free_devs; 619 goto err_unreg_devs;
618 } 620 }
619 621
620 sprintf(db9->phys[i], "%s/input%d", db9->pd->port->name, i); 622 sprintf(db9->phys[i], "%s/input%d", db9->pd->port->name, i);
@@ -640,13 +642,17 @@ static struct db9 __init *db9_probe(int parport, int mode)
640 input_set_abs_params(input_dev, db9_abs[j], 1, 255, 0, 0); 642 input_set_abs_params(input_dev, db9_abs[j], 1, 255, 0, 0);
641 } 643 }
642 644
643 input_register_device(input_dev); 645 err = input_register_device(input_dev);
646 if (err)
647 goto err_free_dev;
644 } 648 }
645 649
646 parport_put_port(pp); 650 parport_put_port(pp);
647 return db9; 651 return db9;
648 652
649 err_free_devs: 653 err_free_dev:
654 input_free_device(db9->dev[i]);
655 err_unreg_devs:
650 while (--i >= 0) 656 while (--i >= 0)
651 input_unregister_device(db9->dev[i]); 657 input_unregister_device(db9->dev[i]);
652 kfree(db9); 658 kfree(db9);
@@ -658,7 +664,7 @@ static struct db9 __init *db9_probe(int parport, int mode)
658 return ERR_PTR(err); 664 return ERR_PTR(err);
659} 665}
660 666
661static void __exit db9_remove(struct db9 *db9) 667static void db9_remove(struct db9 *db9)
662{ 668{
663 int i; 669 int i;
664 670
@@ -696,7 +702,8 @@ static int __init db9_init(void)
696 702
697 if (err) { 703 if (err) {
698 while (--i >= 0) 704 while (--i >= 0)
699 db9_remove(db9_base[i]); 705 if (db9_base[i])
706 db9_remove(db9_base[i]);
700 return err; 707 return err;
701 } 708 }
702 709
diff --git a/drivers/input/joystick/gamecon.c b/drivers/input/joystick/gamecon.c
index 7df2d82f2c83..900587acdb47 100644
--- a/drivers/input/joystick/gamecon.c
+++ b/drivers/input/joystick/gamecon.c
@@ -159,6 +159,48 @@ static void gc_n64_read_packet(struct gc *gc, unsigned char *data)
159 159
160} 160}
161 161
162static void gc_n64_process_packet(struct gc *gc)
163{
164 unsigned char data[GC_N64_LENGTH];
165 signed char axes[2];
166 struct input_dev *dev;
167 int i, j, s;
168
169 gc_n64_read_packet(gc, data);
170
171 for (i = 0; i < GC_MAX_DEVICES; i++) {
172
173 dev = gc->dev[i];
174 if (!dev)
175 continue;
176
177 s = gc_status_bit[i];
178
179 if (s & gc->pads[GC_N64] & ~(data[8] | data[9])) {
180
181 axes[0] = axes[1] = 0;
182
183 for (j = 0; j < 8; j++) {
184 if (data[23 - j] & s)
185 axes[0] |= 1 << j;
186 if (data[31 - j] & s)
187 axes[1] |= 1 << j;
188 }
189
190 input_report_abs(dev, ABS_X, axes[0]);
191 input_report_abs(dev, ABS_Y, -axes[1]);
192
193 input_report_abs(dev, ABS_HAT0X, !(s & data[6]) - !(s & data[7]));
194 input_report_abs(dev, ABS_HAT0Y, !(s & data[4]) - !(s & data[5]));
195
196 for (j = 0; j < 10; j++)
197 input_report_key(dev, gc_n64_btn[j], s & data[gc_n64_bytes[j]]);
198
199 input_sync(dev);
200 }
201 }
202}
203
162/* 204/*
163 * NES/SNES support. 205 * NES/SNES support.
164 */ 206 */
@@ -198,6 +240,39 @@ static void gc_nes_read_packet(struct gc *gc, int length, unsigned char *data)
198 } 240 }
199} 241}
200 242
243static void gc_nes_process_packet(struct gc *gc)
244{
245 unsigned char data[GC_SNES_LENGTH];
246 struct input_dev *dev;
247 int i, j, s;
248
249 gc_nes_read_packet(gc, gc->pads[GC_SNES] ? GC_SNES_LENGTH : GC_NES_LENGTH, data);
250
251 for (i = 0; i < GC_MAX_DEVICES; i++) {
252
253 dev = gc->dev[i];
254 if (!dev)
255 continue;
256
257 s = gc_status_bit[i];
258
259 if (s & (gc->pads[GC_NES] | gc->pads[GC_SNES])) {
260 input_report_abs(dev, ABS_X, !(s & data[6]) - !(s & data[7]));
261 input_report_abs(dev, ABS_Y, !(s & data[4]) - !(s & data[5]));
262 }
263
264 if (s & gc->pads[GC_NES])
265 for (j = 0; j < 4; j++)
266 input_report_key(dev, gc_snes_btn[j], s & data[gc_nes_bytes[j]]);
267
268 if (s & gc->pads[GC_SNES])
269 for (j = 0; j < 8; j++)
270 input_report_key(dev, gc_snes_btn[j], s & data[gc_snes_bytes[j]]);
271
272 input_sync(dev);
273 }
274}
275
201/* 276/*
202 * Multisystem joystick support 277 * Multisystem joystick support
203 */ 278 */
@@ -219,6 +294,35 @@ static void gc_multi_read_packet(struct gc *gc, int length, unsigned char *data)
219 } 294 }
220} 295}
221 296
297static void gc_multi_process_packet(struct gc *gc)
298{
299 unsigned char data[GC_MULTI2_LENGTH];
300 struct input_dev *dev;
301 int i, s;
302
303 gc_multi_read_packet(gc, gc->pads[GC_MULTI2] ? GC_MULTI2_LENGTH : GC_MULTI_LENGTH, data);
304
305 for (i = 0; i < GC_MAX_DEVICES; i++) {
306
307 dev = gc->dev[i];
308 if (!dev)
309 continue;
310
311 s = gc_status_bit[i];
312
313 if (s & (gc->pads[GC_MULTI] | gc->pads[GC_MULTI2])) {
314 input_report_abs(dev, ABS_X, !(s & data[2]) - !(s & data[3]));
315 input_report_abs(dev, ABS_Y, !(s & data[0]) - !(s & data[1]));
316 input_report_key(dev, BTN_TRIGGER, s & data[4]);
317 }
318
319 if (s & gc->pads[GC_MULTI2])
320 input_report_key(dev, BTN_THUMB, s & data[5]);
321
322 input_sync(dev);
323 }
324}
325
222/* 326/*
223 * PSX support 327 * PSX support
224 * 328 *
@@ -263,10 +367,11 @@ static short gc_psx_ddr_btn[] = { BTN_0, BTN_1, BTN_2, BTN_3 };
263 * the psx pad. 367 * the psx pad.
264 */ 368 */
265 369
266static void gc_psx_command(struct gc *gc, int b, unsigned char data[5]) 370static void gc_psx_command(struct gc *gc, int b, unsigned char data[GC_MAX_DEVICES])
267{ 371{
268 int i, j, cmd, read; 372 int i, j, cmd, read;
269 for (i = 0; i < 5; i++) 373
374 for (i = 0; i < GC_MAX_DEVICES; i++)
270 data[i] = 0; 375 data[i] = 0;
271 376
272 for (i = 0; i < GC_PSX_LENGTH; i++, b >>= 1) { 377 for (i = 0; i < GC_PSX_LENGTH; i++, b >>= 1) {
@@ -274,7 +379,7 @@ static void gc_psx_command(struct gc *gc, int b, unsigned char data[5])
274 parport_write_data(gc->pd->port, cmd | GC_PSX_POWER); 379 parport_write_data(gc->pd->port, cmd | GC_PSX_POWER);
275 udelay(gc_psx_delay); 380 udelay(gc_psx_delay);
276 read = parport_read_status(gc->pd->port) ^ 0x80; 381 read = parport_read_status(gc->pd->port) ^ 0x80;
277 for (j = 0; j < 5; j++) 382 for (j = 0; j < GC_MAX_DEVICES; j++)
278 data[j] |= (read & gc_status_bit[j] & (gc->pads[GC_PSX] | gc->pads[GC_DDR])) ? (1 << i) : 0; 383 data[j] |= (read & gc_status_bit[j] & (gc->pads[GC_PSX] | gc->pads[GC_DDR])) ? (1 << i) : 0;
279 parport_write_data(gc->pd->port, cmd | GC_PSX_CLOCK | GC_PSX_POWER); 384 parport_write_data(gc->pd->port, cmd | GC_PSX_CLOCK | GC_PSX_POWER);
280 udelay(gc_psx_delay); 385 udelay(gc_psx_delay);
@@ -286,11 +391,12 @@ static void gc_psx_command(struct gc *gc, int b, unsigned char data[5])
286 * device identifier code. 391 * device identifier code.
287 */ 392 */
288 393
289static void gc_psx_read_packet(struct gc *gc, unsigned char data[5][GC_PSX_BYTES], unsigned char id[5]) 394static void gc_psx_read_packet(struct gc *gc, unsigned char data[GC_MAX_DEVICES][GC_PSX_BYTES],
395 unsigned char id[GC_MAX_DEVICES])
290{ 396{
291 int i, j, max_len = 0; 397 int i, j, max_len = 0;
292 unsigned long flags; 398 unsigned long flags;
293 unsigned char data2[5]; 399 unsigned char data2[GC_MAX_DEVICES];
294 400
295 parport_write_data(gc->pd->port, GC_PSX_CLOCK | GC_PSX_SELECT | GC_PSX_POWER); /* Select pad */ 401 parport_write_data(gc->pd->port, GC_PSX_CLOCK | GC_PSX_SELECT | GC_PSX_POWER); /* Select pad */
296 udelay(gc_psx_delay); 402 udelay(gc_psx_delay);
@@ -303,7 +409,7 @@ static void gc_psx_read_packet(struct gc *gc, unsigned char data[5][GC_PSX_BYTES
303 gc_psx_command(gc, 0x42, id); /* Get device ids */ 409 gc_psx_command(gc, 0x42, id); /* Get device ids */
304 gc_psx_command(gc, 0, data2); /* Dump status */ 410 gc_psx_command(gc, 0, data2); /* Dump status */
305 411
306 for (i =0; i < 5; i++) /* Find the longest pad */ 412 for (i =0; i < GC_MAX_DEVICES; i++) /* Find the longest pad */
307 if((gc_status_bit[i] & (gc->pads[GC_PSX] | gc->pads[GC_DDR])) 413 if((gc_status_bit[i] & (gc->pads[GC_PSX] | gc->pads[GC_DDR]))
308 && (GC_PSX_LEN(id[i]) > max_len) 414 && (GC_PSX_LEN(id[i]) > max_len)
309 && (GC_PSX_LEN(id[i]) <= GC_PSX_BYTES)) 415 && (GC_PSX_LEN(id[i]) <= GC_PSX_BYTES))
@@ -311,7 +417,7 @@ static void gc_psx_read_packet(struct gc *gc, unsigned char data[5][GC_PSX_BYTES
311 417
312 for (i = 0; i < max_len; i++) { /* Read in all the data */ 418 for (i = 0; i < max_len; i++) { /* Read in all the data */
313 gc_psx_command(gc, 0, data2); 419 gc_psx_command(gc, 0, data2);
314 for (j = 0; j < 5; j++) 420 for (j = 0; j < GC_MAX_DEVICES; j++)
315 data[j][i] = data2[j]; 421 data[j][i] = data2[j];
316 } 422 }
317 423
@@ -319,185 +425,124 @@ static void gc_psx_read_packet(struct gc *gc, unsigned char data[5][GC_PSX_BYTES
319 425
320 parport_write_data(gc->pd->port, GC_PSX_CLOCK | GC_PSX_SELECT | GC_PSX_POWER); 426 parport_write_data(gc->pd->port, GC_PSX_CLOCK | GC_PSX_SELECT | GC_PSX_POWER);
321 427
322 for(i = 0; i < 5; i++) /* Set id's to the real value */ 428 for(i = 0; i < GC_MAX_DEVICES; i++) /* Set id's to the real value */
323 id[i] = GC_PSX_ID(id[i]); 429 id[i] = GC_PSX_ID(id[i]);
324} 430}
325 431
326/* 432static void gc_psx_process_packet(struct gc *gc)
327 * gc_timer() reads and analyzes console pads data. 433{
328 */ 434 unsigned char data[GC_MAX_DEVICES][GC_PSX_BYTES];
435 unsigned char id[GC_MAX_DEVICES];
436 struct input_dev *dev;
437 int i, j;
329 438
330#define GC_MAX_LENGTH GC_N64_LENGTH 439 gc_psx_read_packet(gc, data, id);
331 440
332static void gc_timer(unsigned long private) 441 for (i = 0; i < GC_MAX_DEVICES; i++) {
333{
334 struct gc *gc = (void *) private;
335 unsigned char data[GC_MAX_LENGTH];
336 unsigned char data_psx[5][GC_PSX_BYTES];
337 int i, j, s;
338 442
339/* 443 dev = gc->dev[i];
340 * N64 pads - must be read first, any read confuses them for 200 us 444 if (!dev)
341 */ 445 continue;
342 446
343 if (gc->pads[GC_N64]) { 447 switch (id[i]) {
344 448
345 gc_n64_read_packet(gc, data); 449 case GC_PSX_RUMBLE:
346 450
347 for (i = 0; i < 5; i++) { 451 input_report_key(dev, BTN_THUMBL, ~data[i][0] & 0x04);
452 input_report_key(dev, BTN_THUMBR, ~data[i][0] & 0x02);
348 453
349 s = gc_status_bit[i]; 454 case GC_PSX_NEGCON:
455 case GC_PSX_ANALOG:
350 456
351 if (s & gc->pads[GC_N64] & ~(data[8] | data[9])) { 457 if (gc->pads[GC_DDR] & gc_status_bit[i]) {
458 for(j = 0; j < 4; j++)
459 input_report_key(dev, gc_psx_ddr_btn[j], ~data[i][0] & (0x10 << j));
460 } else {
461 for (j = 0; j < 4; j++)
462 input_report_abs(dev, gc_psx_abs[j + 2], data[i][j + 2]);
352 463
353 signed char axes[2]; 464 input_report_abs(dev, ABS_X, 128 + !(data[i][0] & 0x20) * 127 - !(data[i][0] & 0x80) * 128);
354 axes[0] = axes[1] = 0; 465 input_report_abs(dev, ABS_Y, 128 + !(data[i][0] & 0x40) * 127 - !(data[i][0] & 0x10) * 128);
466 }
355 467
356 for (j = 0; j < 8; j++) { 468 for (j = 0; j < 8; j++)
357 if (data[23 - j] & s) axes[0] |= 1 << j; 469 input_report_key(dev, gc_psx_btn[j], ~data[i][1] & (1 << j));
358 if (data[31 - j] & s) axes[1] |= 1 << j; 470
471 input_report_key(dev, BTN_START, ~data[i][0] & 0x08);
472 input_report_key(dev, BTN_SELECT, ~data[i][0] & 0x01);
473
474 input_sync(dev);
475
476 break;
477
478 case GC_PSX_NORMAL:
479 if (gc->pads[GC_DDR] & gc_status_bit[i]) {
480 for(j = 0; j < 4; j++)
481 input_report_key(dev, gc_psx_ddr_btn[j], ~data[i][0] & (0x10 << j));
482 } else {
483 input_report_abs(dev, ABS_X, 128 + !(data[i][0] & 0x20) * 127 - !(data[i][0] & 0x80) * 128);
484 input_report_abs(dev, ABS_Y, 128 + !(data[i][0] & 0x40) * 127 - !(data[i][0] & 0x10) * 128);
485
486 /* for some reason if the extra axes are left unset they drift */
487 /* for (j = 0; j < 4; j++)
488 input_report_abs(dev, gc_psx_abs[j + 2], 128);
489 * This needs to be debugged properly,
490 * maybe fuzz processing needs to be done in input_sync()
491 * --vojtech
492 */
359 } 493 }
360 494
361 input_report_abs(gc->dev[i], ABS_X, axes[0]); 495 for (j = 0; j < 8; j++)
362 input_report_abs(gc->dev[i], ABS_Y, -axes[1]); 496 input_report_key(dev, gc_psx_btn[j], ~data[i][1] & (1 << j));
497
498 input_report_key(dev, BTN_START, ~data[i][0] & 0x08);
499 input_report_key(dev, BTN_SELECT, ~data[i][0] & 0x01);
363 500
364 input_report_abs(gc->dev[i], ABS_HAT0X, !(s & data[6]) - !(s & data[7])); 501 input_sync(dev);
365 input_report_abs(gc->dev[i], ABS_HAT0Y, !(s & data[4]) - !(s & data[5]));
366 502
367 for (j = 0; j < 10; j++) 503 break;
368 input_report_key(gc->dev[i], gc_n64_btn[j], s & data[gc_n64_bytes[j]]);
369 504
370 input_sync(gc->dev[i]); 505 case 0: /* not a pad, ignore */
371 } 506 break;
372 } 507 }
373 } 508 }
509}
374 510
375/* 511/*
376 * NES and SNES pads 512 * gc_timer() initiates reads of console pads data.
377 */ 513 */
378 514
379 if (gc->pads[GC_NES] || gc->pads[GC_SNES]) { 515static void gc_timer(unsigned long private)
380 516{
381 gc_nes_read_packet(gc, gc->pads[GC_SNES] ? GC_SNES_LENGTH : GC_NES_LENGTH, data); 517 struct gc *gc = (void *) private;
382
383 for (i = 0; i < 5; i++) {
384
385 s = gc_status_bit[i];
386 518
387 if (s & (gc->pads[GC_NES] | gc->pads[GC_SNES])) { 519/*
388 input_report_abs(gc->dev[i], ABS_X, !(s & data[6]) - !(s & data[7])); 520 * N64 pads - must be read first, any read confuses them for 200 us
389 input_report_abs(gc->dev[i], ABS_Y, !(s & data[4]) - !(s & data[5])); 521 */
390 }
391 522
392 if (s & gc->pads[GC_NES]) 523 if (gc->pads[GC_N64])
393 for (j = 0; j < 4; j++) 524 gc_n64_process_packet(gc);
394 input_report_key(gc->dev[i], gc_snes_btn[j], s & data[gc_nes_bytes[j]]);
395 525
396 if (s & gc->pads[GC_SNES]) 526/*
397 for (j = 0; j < 8; j++) 527 * NES and SNES pads
398 input_report_key(gc->dev[i], gc_snes_btn[j], s & data[gc_snes_bytes[j]]); 528 */
399 529
400 input_sync(gc->dev[i]); 530 if (gc->pads[GC_NES] || gc->pads[GC_SNES])
401 } 531 gc_nes_process_packet(gc);
402 }
403 532
404/* 533/*
405 * Multi and Multi2 joysticks 534 * Multi and Multi2 joysticks
406 */ 535 */
407 536
408 if (gc->pads[GC_MULTI] || gc->pads[GC_MULTI2]) { 537 if (gc->pads[GC_MULTI] || gc->pads[GC_MULTI2])
409 538 gc_multi_process_packet(gc);
410 gc_multi_read_packet(gc, gc->pads[GC_MULTI2] ? GC_MULTI2_LENGTH : GC_MULTI_LENGTH, data);
411
412 for (i = 0; i < 5; i++) {
413
414 s = gc_status_bit[i];
415
416 if (s & (gc->pads[GC_MULTI] | gc->pads[GC_MULTI2])) {
417 input_report_abs(gc->dev[i], ABS_X, !(s & data[2]) - !(s & data[3]));
418 input_report_abs(gc->dev[i], ABS_Y, !(s & data[0]) - !(s & data[1]));
419 input_report_key(gc->dev[i], BTN_TRIGGER, s & data[4]);
420 }
421
422 if (s & gc->pads[GC_MULTI2])
423 input_report_key(gc->dev[i], BTN_THUMB, s & data[5]);
424
425 input_sync(gc->dev[i]);
426 }
427 }
428 539
429/* 540/*
430 * PSX controllers 541 * PSX controllers
431 */ 542 */
432 543
433 if (gc->pads[GC_PSX] || gc->pads[GC_DDR]) { 544 if (gc->pads[GC_PSX] || gc->pads[GC_DDR])
434 545 gc_psx_process_packet(gc);
435 gc_psx_read_packet(gc, data_psx, data);
436
437 for (i = 0; i < 5; i++) {
438 switch (data[i]) {
439
440 case GC_PSX_RUMBLE:
441
442 input_report_key(gc->dev[i], BTN_THUMBL, ~data_psx[i][0] & 0x04);
443 input_report_key(gc->dev[i], BTN_THUMBR, ~data_psx[i][0] & 0x02);
444
445 case GC_PSX_NEGCON:
446 case GC_PSX_ANALOG:
447
448 if (gc->pads[GC_DDR] & gc_status_bit[i]) {
449 for(j = 0; j < 4; j++)
450 input_report_key(gc->dev[i], gc_psx_ddr_btn[j], ~data_psx[i][0] & (0x10 << j));
451 } else {
452 for (j = 0; j < 4; j++)
453 input_report_abs(gc->dev[i], gc_psx_abs[j+2], data_psx[i][j + 2]);
454
455 input_report_abs(gc->dev[i], ABS_X, 128 + !(data_psx[i][0] & 0x20) * 127 - !(data_psx[i][0] & 0x80) * 128);
456 input_report_abs(gc->dev[i], ABS_Y, 128 + !(data_psx[i][0] & 0x40) * 127 - !(data_psx[i][0] & 0x10) * 128);
457 }
458
459 for (j = 0; j < 8; j++)
460 input_report_key(gc->dev[i], gc_psx_btn[j], ~data_psx[i][1] & (1 << j));
461
462 input_report_key(gc->dev[i], BTN_START, ~data_psx[i][0] & 0x08);
463 input_report_key(gc->dev[i], BTN_SELECT, ~data_psx[i][0] & 0x01);
464
465 input_sync(gc->dev[i]);
466
467 break;
468
469 case GC_PSX_NORMAL:
470 if (gc->pads[GC_DDR] & gc_status_bit[i]) {
471 for(j = 0; j < 4; j++)
472 input_report_key(gc->dev[i], gc_psx_ddr_btn[j], ~data_psx[i][0] & (0x10 << j));
473 } else {
474 input_report_abs(gc->dev[i], ABS_X, 128 + !(data_psx[i][0] & 0x20) * 127 - !(data_psx[i][0] & 0x80) * 128);
475 input_report_abs(gc->dev[i], ABS_Y, 128 + !(data_psx[i][0] & 0x40) * 127 - !(data_psx[i][0] & 0x10) * 128);
476
477 /* for some reason if the extra axes are left unset they drift */
478 /* for (j = 0; j < 4; j++)
479 input_report_abs(gc->dev[i], gc_psx_abs[j+2], 128);
480 * This needs to be debugged properly,
481 * maybe fuzz processing needs to be done in input_sync()
482 * --vojtech
483 */
484 }
485
486 for (j = 0; j < 8; j++)
487 input_report_key(gc->dev[i], gc_psx_btn[j], ~data_psx[i][1] & (1 << j));
488
489 input_report_key(gc->dev[i], BTN_START, ~data_psx[i][0] & 0x08);
490 input_report_key(gc->dev[i], BTN_SELECT, ~data_psx[i][0] & 0x01);
491
492 input_sync(gc->dev[i]);
493
494 break;
495
496 case 0: /* not a pad, ignore */
497 break;
498 }
499 }
500 }
501 546
502 mod_timer(&gc->timer, jiffies + GC_REFRESH_TIME); 547 mod_timer(&gc->timer, jiffies + GC_REFRESH_TIME);
503} 548}
@@ -654,16 +699,18 @@ static struct gc __init *gc_probe(int parport, int *pads, int n_pads)
654 gc->timer.data = (long) gc; 699 gc->timer.data = (long) gc;
655 gc->timer.function = gc_timer; 700 gc->timer.function = gc_timer;
656 701
657 for (i = 0; i < n_pads; i++) { 702 for (i = 0; i < n_pads && i < GC_MAX_DEVICES; i++) {
658 if (!pads[i]) 703 if (!pads[i])
659 continue; 704 continue;
660 705
661 sprintf(gc->phys[i], "%s/input%d", gc->pd->port->name, i); 706 sprintf(gc->phys[i], "%s/input%d", gc->pd->port->name, i);
662 err = gc_setup_pad(gc, i, pads[i]); 707 err = gc_setup_pad(gc, i, pads[i]);
663 if (err) 708 if (err)
664 goto err_free_devs; 709 goto err_unreg_devs;
665 710
666 input_register_device(gc->dev[i]); 711 err = input_register_device(gc->dev[i]);
712 if (err)
713 goto err_free_dev;
667 } 714 }
668 715
669 if (!gc->pads[0]) { 716 if (!gc->pads[0]) {
@@ -675,9 +722,12 @@ static struct gc __init *gc_probe(int parport, int *pads, int n_pads)
675 parport_put_port(pp); 722 parport_put_port(pp);
676 return gc; 723 return gc;
677 724
678 err_free_devs: 725 err_free_dev:
726 input_free_device(gc->dev[i]);
727 err_unreg_devs:
679 while (--i >= 0) 728 while (--i >= 0)
680 input_unregister_device(gc->dev[i]); 729 if (gc->dev[i])
730 input_unregister_device(gc->dev[i]);
681 err_free_gc: 731 err_free_gc:
682 kfree(gc); 732 kfree(gc);
683 err_unreg_pardev: 733 err_unreg_pardev:
@@ -688,7 +738,7 @@ static struct gc __init *gc_probe(int parport, int *pads, int n_pads)
688 return ERR_PTR(err); 738 return ERR_PTR(err);
689} 739}
690 740
691static void __exit gc_remove(struct gc *gc) 741static void gc_remove(struct gc *gc)
692{ 742{
693 int i; 743 int i;
694 744
@@ -726,7 +776,8 @@ static int __init gc_init(void)
726 776
727 if (err) { 777 if (err) {
728 while (--i >= 0) 778 while (--i >= 0)
729 gc_remove(gc_base[i]); 779 if (gc_base[i])
780 gc_remove(gc_base[i]);
730 return err; 781 return err;
731 } 782 }
732 783
diff --git a/drivers/input/joystick/grip.c b/drivers/input/joystick/grip.c
index a936e7aedb10..20cb98ac2d79 100644
--- a/drivers/input/joystick/grip.c
+++ b/drivers/input/joystick/grip.c
@@ -192,6 +192,9 @@ static void grip_poll(struct gameport *gameport)
192 for (i = 0; i < 2; i++) { 192 for (i = 0; i < 2; i++) {
193 193
194 dev = grip->dev[i]; 194 dev = grip->dev[i];
195 if (!dev)
196 continue;
197
195 grip->reads++; 198 grip->reads++;
196 199
197 switch (grip->mode[i]) { 200 switch (grip->mode[i]) {
@@ -381,12 +384,15 @@ static int grip_connect(struct gameport *gameport, struct gameport_driver *drv)
381 if (t > 0) 384 if (t > 0)
382 set_bit(t, input_dev->keybit); 385 set_bit(t, input_dev->keybit);
383 386
384 input_register_device(grip->dev[i]); 387 err = input_register_device(grip->dev[i]);
388 if (err)
389 goto fail4;
385 } 390 }
386 391
387 return 0; 392 return 0;
388 393
389 fail3: for (i = 0; i < 2; i++) 394 fail4: input_free_device(grip->dev[i]);
395 fail3: while (--i >= 0)
390 if (grip->dev[i]) 396 if (grip->dev[i])
391 input_unregister_device(grip->dev[i]); 397 input_unregister_device(grip->dev[i]);
392 fail2: gameport_close(gameport); 398 fail2: gameport_close(gameport);
@@ -411,6 +417,7 @@ static void grip_disconnect(struct gameport *gameport)
411static struct gameport_driver grip_drv = { 417static struct gameport_driver grip_drv = {
412 .driver = { 418 .driver = {
413 .name = "grip", 419 .name = "grip",
420 .owner = THIS_MODULE,
414 }, 421 },
415 .description = DRIVER_DESC, 422 .description = DRIVER_DESC,
416 .connect = grip_connect, 423 .connect = grip_connect,
diff --git a/drivers/input/joystick/iforce/iforce-main.c b/drivers/input/joystick/iforce/iforce-main.c
index 64b9c31c47fc..b6bc04998047 100644
--- a/drivers/input/joystick/iforce/iforce-main.c
+++ b/drivers/input/joystick/iforce/iforce-main.c
@@ -345,7 +345,7 @@ int iforce_init_device(struct iforce *iforce)
345 int i; 345 int i;
346 346
347 input_dev = input_allocate_device(); 347 input_dev = input_allocate_device();
348 if (input_dev) 348 if (!input_dev)
349 return -ENOMEM; 349 return -ENOMEM;
350 350
351 init_waitqueue_head(&iforce->wait); 351 init_waitqueue_head(&iforce->wait);
diff --git a/drivers/input/joystick/iforce/iforce-packets.c b/drivers/input/joystick/iforce/iforce-packets.c
index 4a2629243e19..76cb1f88f4e8 100644
--- a/drivers/input/joystick/iforce/iforce-packets.c
+++ b/drivers/input/joystick/iforce/iforce-packets.c
@@ -167,9 +167,9 @@ void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data,
167 iforce->expect_packet = 0; 167 iforce->expect_packet = 0;
168 iforce->ecmd = cmd; 168 iforce->ecmd = cmd;
169 memcpy(iforce->edata, data, IFORCE_MAX_LENGTH); 169 memcpy(iforce->edata, data, IFORCE_MAX_LENGTH);
170 wake_up(&iforce->wait);
171 } 170 }
172#endif 171#endif
172 wake_up(&iforce->wait);
173 173
174 if (!iforce->type) { 174 if (!iforce->type) {
175 being_used--; 175 being_used--;
@@ -264,7 +264,7 @@ int iforce_get_id_packet(struct iforce *iforce, char *packet)
264 wait_event_interruptible_timeout(iforce->wait, 264 wait_event_interruptible_timeout(iforce->wait,
265 iforce->ctrl->status != -EINPROGRESS, HZ); 265 iforce->ctrl->status != -EINPROGRESS, HZ);
266 266
267 if (iforce->ctrl->status != -EINPROGRESS) { 267 if (iforce->ctrl->status) {
268 usb_unlink_urb(iforce->ctrl); 268 usb_unlink_urb(iforce->ctrl);
269 return -1; 269 return -1;
270 } 270 }
diff --git a/drivers/input/joystick/iforce/iforce-usb.c b/drivers/input/joystick/iforce/iforce-usb.c
index bc2fce60f9f8..fe79d158456d 100644
--- a/drivers/input/joystick/iforce/iforce-usb.c
+++ b/drivers/input/joystick/iforce/iforce-usb.c
@@ -95,7 +95,6 @@ static void iforce_usb_irq(struct urb *urb, struct pt_regs *regs)
95 goto exit; 95 goto exit;
96 } 96 }
97 97
98 wake_up(&iforce->wait);
99 iforce_process_packet(iforce, 98 iforce_process_packet(iforce,
100 (iforce->data[0] << 8) | (urb->actual_length - 1), iforce->data + 1, regs); 99 (iforce->data[0] << 8) | (urb->actual_length - 1), iforce->data + 1, regs);
101 100
diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
index 78dd163cd702..2b2ec1057dee 100644
--- a/drivers/input/joystick/sidewinder.c
+++ b/drivers/input/joystick/sidewinder.c
@@ -736,7 +736,7 @@ static int sw_connect(struct gameport *gameport, struct gameport_driver *drv)
736 sprintf(sw->name, "Microsoft SideWinder %s", sw_name[sw->type]); 736 sprintf(sw->name, "Microsoft SideWinder %s", sw_name[sw->type]);
737 sprintf(sw->phys[i], "%s/input%d", gameport->phys, i); 737 sprintf(sw->phys[i], "%s/input%d", gameport->phys, i);
738 738
739 input_dev = input_allocate_device(); 739 sw->dev[i] = input_dev = input_allocate_device();
740 if (!input_dev) { 740 if (!input_dev) {
741 err = -ENOMEM; 741 err = -ENOMEM;
742 goto fail3; 742 goto fail3;
@@ -771,12 +771,15 @@ static int sw_connect(struct gameport *gameport, struct gameport_driver *drv)
771 771
772 dbg("%s%s [%d-bit id %d data %d]\n", sw->name, comment, m, l, k); 772 dbg("%s%s [%d-bit id %d data %d]\n", sw->name, comment, m, l, k);
773 773
774 input_register_device(sw->dev[i]); 774 err = input_register_device(sw->dev[i]);
775 if (err)
776 goto fail4;
775 } 777 }
776 778
777 return 0; 779 return 0;
778 780
779 fail3: while (--i >= 0) 781 fail4: input_free_device(sw->dev[i]);
782 fail3: while (--i >= 0)
780 input_unregister_device(sw->dev[i]); 783 input_unregister_device(sw->dev[i]);
781 fail2: gameport_close(gameport); 784 fail2: gameport_close(gameport);
782 fail1: gameport_set_drvdata(gameport, NULL); 785 fail1: gameport_set_drvdata(gameport, NULL);
@@ -801,6 +804,7 @@ static void sw_disconnect(struct gameport *gameport)
801static struct gameport_driver sw_drv = { 804static struct gameport_driver sw_drv = {
802 .driver = { 805 .driver = {
803 .name = "sidewinder", 806 .name = "sidewinder",
807 .owner = THIS_MODULE,
804 }, 808 },
805 .description = DRIVER_DESC, 809 .description = DRIVER_DESC,
806 .connect = sw_connect, 810 .connect = sw_connect,
diff --git a/drivers/input/joystick/tmdc.c b/drivers/input/joystick/tmdc.c
index 60e2aac7d06e..bb23ed2a04a6 100644
--- a/drivers/input/joystick/tmdc.c
+++ b/drivers/input/joystick/tmdc.c
@@ -284,13 +284,13 @@ static int tmdc_setup_port(struct tmdc *tmdc, int idx, unsigned char *data)
284 struct tmdc_port *port; 284 struct tmdc_port *port;
285 struct input_dev *input_dev; 285 struct input_dev *input_dev;
286 int i, j, b = 0; 286 int i, j, b = 0;
287 int err;
287 288
288 tmdc->port[idx] = port = kzalloc(sizeof (struct tmdc_port), GFP_KERNEL); 289 tmdc->port[idx] = port = kzalloc(sizeof (struct tmdc_port), GFP_KERNEL);
289 input_dev = input_allocate_device(); 290 input_dev = input_allocate_device();
290 if (!port || !input_dev) { 291 if (!port || !input_dev) {
291 kfree(port); 292 err = -ENOMEM;
292 input_free_device(input_dev); 293 goto fail;
293 return -ENOMEM;
294 } 294 }
295 295
296 port->mode = data[TMDC_BYTE_ID]; 296 port->mode = data[TMDC_BYTE_ID];
@@ -347,9 +347,15 @@ static int tmdc_setup_port(struct tmdc *tmdc, int idx, unsigned char *data)
347 b += port->btnc[i]; 347 b += port->btnc[i];
348 } 348 }
349 349
350 input_register_device(port->dev); 350 err = input_register_device(port->dev);
351 if (err)
352 goto fail;
351 353
352 return 0; 354 return 0;
355
356 fail: input_free_device(input_dev);
357 kfree(port);
358 return err;
353} 359}
354 360
355/* 361/*
@@ -424,6 +430,7 @@ static void tmdc_disconnect(struct gameport *gameport)
424static struct gameport_driver tmdc_drv = { 430static struct gameport_driver tmdc_drv = {
425 .driver = { 431 .driver = {
426 .name = "tmdc", 432 .name = "tmdc",
433 .owner = THIS_MODULE,
427 }, 434 },
428 .description = DRIVER_DESC, 435 .description = DRIVER_DESC,
429 .connect = tmdc_connect, 436 .connect = tmdc_connect,
diff --git a/drivers/input/joystick/turbografx.c b/drivers/input/joystick/turbografx.c
index 7e9764937d06..b154938e88a4 100644
--- a/drivers/input/joystick/turbografx.c
+++ b/drivers/input/joystick/turbografx.c
@@ -204,14 +204,14 @@ static struct tgfx __init *tgfx_probe(int parport, int *n_buttons, int n_devs)
204 if (n_buttons[i] > 6) { 204 if (n_buttons[i] > 6) {
205 printk(KERN_ERR "turbografx.c: Invalid number of buttons %d\n", n_buttons[i]); 205 printk(KERN_ERR "turbografx.c: Invalid number of buttons %d\n", n_buttons[i]);
206 err = -EINVAL; 206 err = -EINVAL;
207 goto err_free_devs; 207 goto err_unreg_devs;
208 } 208 }
209 209
210 tgfx->dev[i] = input_dev = input_allocate_device(); 210 tgfx->dev[i] = input_dev = input_allocate_device();
211 if (!input_dev) { 211 if (!input_dev) {
212 printk(KERN_ERR "turbografx.c: Not enough memory for input device\n"); 212 printk(KERN_ERR "turbografx.c: Not enough memory for input device\n");
213 err = -ENOMEM; 213 err = -ENOMEM;
214 goto err_free_devs; 214 goto err_unreg_devs;
215 } 215 }
216 216
217 tgfx->sticks |= (1 << i); 217 tgfx->sticks |= (1 << i);
@@ -238,7 +238,9 @@ static struct tgfx __init *tgfx_probe(int parport, int *n_buttons, int n_devs)
238 for (j = 0; j < n_buttons[i]; j++) 238 for (j = 0; j < n_buttons[i]; j++)
239 set_bit(tgfx_buttons[j], input_dev->keybit); 239 set_bit(tgfx_buttons[j], input_dev->keybit);
240 240
241 input_register_device(tgfx->dev[i]); 241 err = input_register_device(tgfx->dev[i]);
242 if (err)
243 goto err_free_dev;
242 } 244 }
243 245
244 if (!tgfx->sticks) { 246 if (!tgfx->sticks) {
@@ -249,9 +251,12 @@ static struct tgfx __init *tgfx_probe(int parport, int *n_buttons, int n_devs)
249 251
250 return tgfx; 252 return tgfx;
251 253
252 err_free_devs: 254 err_free_dev:
255 input_free_device(tgfx->dev[i]);
256 err_unreg_devs:
253 while (--i >= 0) 257 while (--i >= 0)
254 input_unregister_device(tgfx->dev[i]); 258 if (tgfx->dev[i])
259 input_unregister_device(tgfx->dev[i]);
255 err_free_tgfx: 260 err_free_tgfx:
256 kfree(tgfx); 261 kfree(tgfx);
257 err_unreg_pardev: 262 err_unreg_pardev:
@@ -262,7 +267,7 @@ static struct tgfx __init *tgfx_probe(int parport, int *n_buttons, int n_devs)
262 return ERR_PTR(err); 267 return ERR_PTR(err);
263} 268}
264 269
265static void __exit tgfx_remove(struct tgfx *tgfx) 270static void tgfx_remove(struct tgfx *tgfx)
266{ 271{
267 int i; 272 int i;
268 273
@@ -300,7 +305,8 @@ static int __init tgfx_init(void)
300 305
301 if (err) { 306 if (err) {
302 while (--i >= 0) 307 while (--i >= 0)
303 tgfx_remove(tgfx_base[i]); 308 if (tgfx_base[i])
309 tgfx_remove(tgfx_base[i]);
304 return err; 310 return err;
305 } 311 }
306 312
diff --git a/drivers/input/joystick/twidjoy.c b/drivers/input/joystick/twidjoy.c
index cd3a1e742a30..7f8b0093c5bc 100644
--- a/drivers/input/joystick/twidjoy.c
+++ b/drivers/input/joystick/twidjoy.c
@@ -265,13 +265,13 @@ static struct serio_driver twidjoy_drv = {
265 * The functions for inserting/removing us as a module. 265 * The functions for inserting/removing us as a module.
266 */ 266 */
267 267
268int __init twidjoy_init(void) 268static int __init twidjoy_init(void)
269{ 269{
270 serio_register_driver(&twidjoy_drv); 270 serio_register_driver(&twidjoy_drv);
271 return 0; 271 return 0;
272} 272}
273 273
274void __exit twidjoy_exit(void) 274static void __exit twidjoy_exit(void)
275{ 275{
276 serio_unregister_driver(&twidjoy_drv); 276 serio_unregister_driver(&twidjoy_drv);
277} 277}