aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/joystick/db9.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/input/joystick/db9.c')
-rw-r--r--drivers/input/joystick/db9.c292
1 files changed, 176 insertions, 116 deletions
diff --git a/drivers/input/joystick/db9.c b/drivers/input/joystick/db9.c
index 2a3e4bb2da50..499344c72756 100644
--- a/drivers/input/joystick/db9.c
+++ b/drivers/input/joystick/db9.c
@@ -43,25 +43,28 @@ MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
43MODULE_DESCRIPTION("Atari, Amstrad, Commodore, Amiga, Sega, etc. joystick driver"); 43MODULE_DESCRIPTION("Atari, Amstrad, Commodore, Amiga, Sega, etc. joystick driver");
44MODULE_LICENSE("GPL"); 44MODULE_LICENSE("GPL");
45 45
46static int db9[] __initdata = { -1, 0 }; 46struct db9_config {
47static int db9_nargs __initdata = 0; 47 int args[2];
48module_param_array_named(dev, db9, int, &db9_nargs, 0); 48 int nargs;
49MODULE_PARM_DESC(dev, "Describes first attached device (<parport#>,<type>)"); 49};
50 50
51static int db9_2[] __initdata = { -1, 0 }; 51#define DB9_MAX_PORTS 3
52static int db9_nargs_2 __initdata = 0; 52static struct db9_config db9[DB9_MAX_PORTS] __initdata;
53module_param_array_named(dev2, db9_2, int, &db9_nargs_2, 0);
54MODULE_PARM_DESC(dev2, "Describes second attached device (<parport#>,<type>)");
55 53
56static int db9_3[] __initdata = { -1, 0 }; 54module_param_array_named(dev, db9[0].args, int, &db9[0].nargs, 0);
57static int db9_nargs_3 __initdata = 0; 55MODULE_PARM_DESC(dev, "Describes first attached device (<parport#>,<type>)");
58module_param_array_named(dev3, db9_3, int, &db9_nargs_3, 0); 56module_param_array_named(dev2, db9[1].args, int, &db9[0].nargs, 0);
57MODULE_PARM_DESC(dev2, "Describes second attached device (<parport#>,<type>)");
58module_param_array_named(dev3, db9[2].args, int, &db9[2].nargs, 0);
59MODULE_PARM_DESC(dev3, "Describes third attached device (<parport#>,<type>)"); 59MODULE_PARM_DESC(dev3, "Describes third attached device (<parport#>,<type>)");
60 60
61__obsolete_setup("db9="); 61__obsolete_setup("db9=");
62__obsolete_setup("db9_2="); 62__obsolete_setup("db9_2=");
63__obsolete_setup("db9_3="); 63__obsolete_setup("db9_3=");
64 64
65#define DB9_ARG_PARPORT 0
66#define DB9_ARG_MODE 1
67
65#define DB9_MULTI_STICK 0x01 68#define DB9_MULTI_STICK 0x01
66#define DB9_MULTI2_STICK 0x02 69#define DB9_MULTI2_STICK 0x02
67#define DB9_GENESIS_PAD 0x03 70#define DB9_GENESIS_PAD 0x03
@@ -87,40 +90,53 @@ __obsolete_setup("db9_3=");
87#define DB9_NORMAL 0x0a 90#define DB9_NORMAL 0x0a
88#define DB9_NOSELECT 0x08 91#define DB9_NOSELECT 0x08
89 92
90#define DB9_MAX_DEVICES 2
91
92#define DB9_GENESIS6_DELAY 14 93#define DB9_GENESIS6_DELAY 14
93#define DB9_REFRESH_TIME HZ/100 94#define DB9_REFRESH_TIME HZ/100
94 95
96#define DB9_MAX_DEVICES 2
97
98struct db9_mode_data {
99 const char *name;
100 const short *buttons;
101 int n_buttons;
102 int n_pads;
103 int n_axis;
104 int bidirectional;
105 int reverse;
106};
107
95struct db9 { 108struct db9 {
96 struct input_dev dev[DB9_MAX_DEVICES]; 109 struct input_dev *dev[DB9_MAX_DEVICES];
97 struct timer_list timer; 110 struct timer_list timer;
98 struct pardevice *pd; 111 struct pardevice *pd;
99 int mode; 112 int mode;
100 int used; 113 int used;
101 struct semaphore sem; 114 struct semaphore sem;
102 char phys[2][32]; 115 char phys[DB9_MAX_DEVICES][32];
103}; 116};
104 117
105static struct db9 *db9_base[3]; 118static struct db9 *db9_base[3];
106 119
107static short db9_multi_btn[] = { BTN_TRIGGER, BTN_THUMB }; 120static const short db9_multi_btn[] = { BTN_TRIGGER, BTN_THUMB };
108static short db9_genesis_btn[] = { BTN_START, BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_MODE }; 121static const short db9_genesis_btn[] = { BTN_START, BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_MODE };
109static short db9_cd32_btn[] = { BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_TL, BTN_TR, BTN_START }; 122static const short db9_cd32_btn[] = { BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_TL, BTN_TR, BTN_START };
110
111static char db9_buttons[DB9_MAX_PAD] = { 0, 1, 2, 4, 0, 6, 8, 9, 1, 1, 7, 9, 9 };
112static short *db9_btn[DB9_MAX_PAD] = { NULL, db9_multi_btn, db9_multi_btn, db9_genesis_btn, NULL, db9_genesis_btn,
113 db9_genesis_btn, db9_cd32_btn, db9_multi_btn, db9_multi_btn, db9_cd32_btn,
114 db9_cd32_btn, db9_cd32_btn };
115static char *db9_name[DB9_MAX_PAD] = { NULL, "Multisystem joystick", "Multisystem joystick (2 fire)", "Genesis pad",
116 NULL, "Genesis 5 pad", "Genesis 6 pad", "Saturn pad", "Multisystem (0.8.0.2) joystick",
117 "Multisystem (0.8.0.2-dual) joystick", "Amiga CD-32 pad", "Saturn dpp", "Saturn dpp dual" };
118
119static const int db9_max_pads[DB9_MAX_PAD] = { 0, 1, 1, 1, 0, 1, 1, 6, 1, 2, 1, 6, 12 };
120static const int db9_num_axis[DB9_MAX_PAD] = { 0, 2, 2, 2, 0, 2, 2, 7, 2, 2, 2 ,7, 7 };
121static const short db9_abs[] = { ABS_X, ABS_Y, ABS_RX, ABS_RY, ABS_RZ, ABS_Z, ABS_HAT0X, ABS_HAT0Y, ABS_HAT1X, ABS_HAT1Y }; 123static const short db9_abs[] = { ABS_X, ABS_Y, ABS_RX, ABS_RY, ABS_RZ, ABS_Z, ABS_HAT0X, ABS_HAT0Y, ABS_HAT1X, ABS_HAT1Y };
122static const int db9_bidirectional[DB9_MAX_PAD] = { 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0 }; 124
123static const int db9_reverse[DB9_MAX_PAD] = { 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0 }; 125static const struct db9_mode_data db9_modes[] = {
126 { NULL, NULL, 0, 0, 0, 0, 0 },
127 { "Multisystem joystick", db9_multi_btn, 1, 1, 2, 1, 1 },
128 { "Multisystem joystick (2 fire)", db9_multi_btn, 2, 1, 2, 1, 1 },
129 { "Genesis pad", db9_genesis_btn, 4, 1, 2, 1, 1 },
130 { NULL, NULL, 0, 0, 0, 0, 0 },
131 { "Genesis 5 pad", db9_genesis_btn, 6, 1, 2, 1, 1 },
132 { "Genesis 6 pad", db9_genesis_btn, 8, 1, 2, 1, 1 },
133 { "Saturn pad", db9_cd32_btn, 9, 6, 7, 0, 1 },
134 { "Multisystem (0.8.0.2) joystick", db9_multi_btn, 1, 1, 2, 1, 1 },
135 { "Multisystem (0.8.0.2-dual) joystick", db9_multi_btn, 1, 2, 2, 1, 1 },
136 { "Amiga CD-32 pad", db9_cd32_btn, 7, 1, 2, 1, 1 },
137 { "Saturn dpp", db9_cd32_btn, 9, 6, 7, 0, 0 },
138 { "Saturn dpp dual", db9_cd32_btn, 9, 12, 7, 0, 0 },
139};
124 140
125/* 141/*
126 * Saturn controllers 142 * Saturn controllers
@@ -342,7 +358,7 @@ static int db9_saturn(int mode, struct parport *port, struct input_dev *dev)
342 default: 358 default:
343 return -1; 359 return -1;
344 } 360 }
345 max_pads = min(db9_max_pads[mode], DB9_MAX_DEVICES); 361 max_pads = min(db9_modes[mode].n_pads, DB9_MAX_DEVICES);
346 for (tmp = 0, i = 0; i < n; i++) { 362 for (tmp = 0, i = 0; i < n; i++) {
347 id = db9_saturn_read_packet(port, data, type + i, 1); 363 id = db9_saturn_read_packet(port, data, type + i, 1);
348 tmp = db9_saturn_report(id, data, dev, tmp, max_pads); 364 tmp = db9_saturn_report(id, data, dev, tmp, max_pads);
@@ -354,17 +370,18 @@ static void db9_timer(unsigned long private)
354{ 370{
355 struct db9 *db9 = (void *) private; 371 struct db9 *db9 = (void *) private;
356 struct parport *port = db9->pd->port; 372 struct parport *port = db9->pd->port;
357 struct input_dev *dev = db9->dev; 373 struct input_dev *dev = db9->dev[0];
374 struct input_dev *dev2 = db9->dev[1];
358 int data, i; 375 int data, i;
359 376
360 switch(db9->mode) { 377 switch (db9->mode) {
361 case DB9_MULTI_0802_2: 378 case DB9_MULTI_0802_2:
362 379
363 data = parport_read_data(port) >> 3; 380 data = parport_read_data(port) >> 3;
364 381
365 input_report_abs(dev + 1, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1)); 382 input_report_abs(dev2, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1));
366 input_report_abs(dev + 1, ABS_Y, (data & DB9_DOWN ? 0 : 1) - (data & DB9_UP ? 0 : 1)); 383 input_report_abs(dev2, ABS_Y, (data & DB9_DOWN ? 0 : 1) - (data & DB9_UP ? 0 : 1));
367 input_report_key(dev + 1, BTN_TRIGGER, ~data & DB9_FIRE1); 384 input_report_key(dev2, BTN_TRIGGER, ~data & DB9_FIRE1);
368 385
369 case DB9_MULTI_0802: 386 case DB9_MULTI_0802:
370 387
@@ -405,7 +422,7 @@ static void db9_timer(unsigned long private)
405 input_report_key(dev, BTN_C, ~data & DB9_FIRE2); 422 input_report_key(dev, BTN_C, ~data & DB9_FIRE2);
406 423
407 parport_write_control(port, DB9_NORMAL); 424 parport_write_control(port, DB9_NORMAL);
408 data=parport_read_data(port); 425 data = parport_read_data(port);
409 426
410 input_report_key(dev, BTN_A, ~data & DB9_FIRE1); 427 input_report_key(dev, BTN_A, ~data & DB9_FIRE1);
411 input_report_key(dev, BTN_START, ~data & DB9_FIRE2); 428 input_report_key(dev, BTN_START, ~data & DB9_FIRE2);
@@ -414,7 +431,7 @@ static void db9_timer(unsigned long private)
414 case DB9_GENESIS5_PAD: 431 case DB9_GENESIS5_PAD:
415 432
416 parport_write_control(port, DB9_NOSELECT); 433 parport_write_control(port, DB9_NOSELECT);
417 data=parport_read_data(port); 434 data = parport_read_data(port);
418 435
419 input_report_abs(dev, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1)); 436 input_report_abs(dev, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1));
420 input_report_abs(dev, ABS_Y, (data & DB9_DOWN ? 0 : 1) - (data & DB9_UP ? 0 : 1)); 437 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 input_report_key(dev, BTN_C, ~data & DB9_FIRE2); 439 input_report_key(dev, BTN_C, ~data & DB9_FIRE2);
423 440
424 parport_write_control(port, DB9_NORMAL); 441 parport_write_control(port, DB9_NORMAL);
425 data=parport_read_data(port); 442 data = parport_read_data(port);
426 443
427 input_report_key(dev, BTN_A, ~data & DB9_FIRE1); 444 input_report_key(dev, BTN_A, ~data & DB9_FIRE1);
428 input_report_key(dev, BTN_X, ~data & DB9_FIRE2); 445 input_report_key(dev, BTN_X, ~data & DB9_FIRE2);
@@ -434,7 +451,7 @@ static void db9_timer(unsigned long private)
434 451
435 parport_write_control(port, DB9_NOSELECT); /* 1 */ 452 parport_write_control(port, DB9_NOSELECT); /* 1 */
436 udelay(DB9_GENESIS6_DELAY); 453 udelay(DB9_GENESIS6_DELAY);
437 data=parport_read_data(port); 454 data = parport_read_data(port);
438 455
439 input_report_abs(dev, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1)); 456 input_report_abs(dev, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1));
440 input_report_abs(dev, ABS_Y, (data & DB9_DOWN ? 0 : 1) - (data & DB9_UP ? 0 : 1)); 457 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 460
444 parport_write_control(port, DB9_NORMAL); 461 parport_write_control(port, DB9_NORMAL);
445 udelay(DB9_GENESIS6_DELAY); 462 udelay(DB9_GENESIS6_DELAY);
446 data=parport_read_data(port); 463 data = parport_read_data(port);
447 464
448 input_report_key(dev, BTN_A, ~data & DB9_FIRE1); 465 input_report_key(dev, BTN_A, ~data & DB9_FIRE1);
449 input_report_key(dev, BTN_START, ~data & DB9_FIRE2); 466 input_report_key(dev, BTN_START, ~data & DB9_FIRE2);
@@ -477,7 +494,7 @@ static void db9_timer(unsigned long private)
477 494
478 case DB9_CD32_PAD: 495 case DB9_CD32_PAD:
479 496
480 data=parport_read_data(port); 497 data = parport_read_data(port);
481 498
482 input_report_abs(dev, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1)); 499 input_report_abs(dev, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1));
483 input_report_abs(dev, ABS_Y, (data & DB9_DOWN ? 0 : 1) - (data & DB9_UP ? 0 : 1)); 500 input_report_abs(dev, ABS_Y, (data & DB9_DOWN ? 0 : 1) - (data & DB9_UP ? 0 : 1));
@@ -489,7 +506,7 @@ static void db9_timer(unsigned long private)
489 parport_write_control(port, 0x02); 506 parport_write_control(port, 0x02);
490 parport_write_control(port, 0x0a); 507 parport_write_control(port, 0x0a);
491 input_report_key(dev, db9_cd32_btn[i], ~data & DB9_FIRE2); 508 input_report_key(dev, db9_cd32_btn[i], ~data & DB9_FIRE2);
492 } 509 }
493 510
494 parport_write_control(port, 0x00); 511 parport_write_control(port, 0x00);
495 break; 512 break;
@@ -513,7 +530,7 @@ static int db9_open(struct input_dev *dev)
513 if (!db9->used++) { 530 if (!db9->used++) {
514 parport_claim(db9->pd); 531 parport_claim(db9->pd);
515 parport_write_data(port, 0xff); 532 parport_write_data(port, 0xff);
516 if (db9_reverse[db9->mode]) { 533 if (db9_modes[db9->mode].reverse) {
517 parport_data_reverse(port); 534 parport_data_reverse(port);
518 parport_write_control(port, DB9_NORMAL); 535 parport_write_control(port, DB9_NORMAL);
519 } 536 }
@@ -539,117 +556,160 @@ static void db9_close(struct input_dev *dev)
539 up(&db9->sem); 556 up(&db9->sem);
540} 557}
541 558
542static struct db9 __init *db9_probe(int *config, int nargs) 559static struct db9 __init *db9_probe(int parport, int mode)
543{ 560{
544 struct db9 *db9; 561 struct db9 *db9;
562 const struct db9_mode_data *db9_mode;
545 struct parport *pp; 563 struct parport *pp;
564 struct pardevice *pd;
565 struct input_dev *input_dev;
546 int i, j; 566 int i, j;
567 int err;
547 568
548 if (config[0] < 0) 569 if (mode < 1 || mode >= DB9_MAX_PAD || !db9_modes[mode].n_buttons) {
549 return NULL; 570 printk(KERN_ERR "db9.c: Bad device type %d\n", mode);
550 571 err = -EINVAL;
551 if (nargs < 2) { 572 goto err_out;
552 printk(KERN_ERR "db9.c: Device type must be specified.\n");
553 return NULL;
554 } 573 }
555 574
556 if (config[1] < 1 || config[1] >= DB9_MAX_PAD || !db9_buttons[config[1]]) { 575 db9_mode = &db9_modes[mode];
557 printk(KERN_ERR "db9.c: bad config\n");
558 return NULL;
559 }
560 576
561 pp = parport_find_number(config[0]); 577 pp = parport_find_number(parport);
562 if (!pp) { 578 if (!pp) {
563 printk(KERN_ERR "db9.c: no such parport\n"); 579 printk(KERN_ERR "db9.c: no such parport\n");
564 return NULL; 580 err = -ENODEV;
581 goto err_out;
565 } 582 }
566 583
567 if (db9_bidirectional[config[1]]) { 584 if (db9_mode[mode].bidirectional && !(pp->modes & PARPORT_MODE_TRISTATE)) {
568 if (!(pp->modes & PARPORT_MODE_TRISTATE)) { 585 printk(KERN_ERR "db9.c: specified parport is not bidirectional\n");
569 printk(KERN_ERR "db9.c: specified parport is not bidirectional\n"); 586 err = -EINVAL;
570 parport_put_port(pp); 587 goto err_put_pp;
571 return NULL; 588 }
572 } 589
590 pd = parport_register_device(pp, "db9", NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL);
591 if (!pd) {
592 printk(KERN_ERR "db9.c: parport busy already - lp.o loaded?\n");
593 err = -EBUSY;
594 goto err_put_pp;
573 } 595 }
574 596
575 if (!(db9 = kzalloc(sizeof(struct db9), GFP_KERNEL))) { 597 db9 = kzalloc(sizeof(struct db9), GFP_KERNEL);
576 parport_put_port(pp); 598 if (!db9) {
577 return NULL; 599 printk(KERN_ERR "db9.c: Not enough memory\n");
600 err = -ENOMEM;
601 goto err_unreg_pardev;
578 } 602 }
579 603
580 init_MUTEX(&db9->sem); 604 init_MUTEX(&db9->sem);
581 db9->mode = config[1]; 605 db9->pd = pd;
606 db9->mode = mode;
582 init_timer(&db9->timer); 607 init_timer(&db9->timer);
583 db9->timer.data = (long) db9; 608 db9->timer.data = (long) db9;
584 db9->timer.function = db9_timer; 609 db9->timer.function = db9_timer;
585 610
586 db9->pd = parport_register_device(pp, "db9", NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL); 611 for (i = 0; i < (min(db9_mode->n_pads, DB9_MAX_DEVICES)); i++) {
587 parport_put_port(pp);
588
589 if (!db9->pd) {
590 printk(KERN_ERR "db9.c: parport busy already - lp.o loaded?\n");
591 kfree(db9);
592 return NULL;
593 }
594 612
595 for (i = 0; i < (min(db9_max_pads[db9->mode], DB9_MAX_DEVICES)); i++) { 613 db9->dev[i] = input_dev = input_allocate_device();
614 if (!input_dev) {
615 printk(KERN_ERR "db9.c: Not enough memory for input device\n");
616 err = -ENOMEM;
617 goto err_free_devs;
618 }
596 619
597 sprintf(db9->phys[i], "%s/input%d", db9->pd->port->name, i); 620 sprintf(db9->phys[i], "%s/input%d", db9->pd->port->name, i);
598 621
599 db9->dev[i].private = db9; 622 input_dev->name = db9_mode->name;
600 db9->dev[i].open = db9_open; 623 input_dev->phys = db9->phys[i];
601 db9->dev[i].close = db9_close; 624 input_dev->id.bustype = BUS_PARPORT;
602 625 input_dev->id.vendor = 0x0002;
603 db9->dev[i].name = db9_name[db9->mode]; 626 input_dev->id.product = mode;
604 db9->dev[i].phys = db9->phys[i]; 627 input_dev->id.version = 0x0100;
605 db9->dev[i].id.bustype = BUS_PARPORT; 628 input_dev->private = db9;
606 db9->dev[i].id.vendor = 0x0002; 629
607 db9->dev[i].id.product = config[1]; 630 input_dev->open = db9_open;
608 db9->dev[i].id.version = 0x0100; 631 input_dev->close = db9_close;
609 632
610 db9->dev[i].evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 633 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
611 for (j = 0; j < db9_buttons[db9->mode]; j++) 634 for (j = 0; j < db9_mode->n_buttons; j++)
612 set_bit(db9_btn[db9->mode][j], db9->dev[i].keybit); 635 set_bit(db9_mode->buttons[j], input_dev->keybit);
613 for (j = 0; j < db9_num_axis[db9->mode]; j++) { 636 for (j = 0; j < db9_mode->n_axis; j++) {
614 set_bit(db9_abs[j], db9->dev[i].absbit); 637 if (j < 2)
615 if (j < 2) { 638 input_set_abs_params(input_dev, db9_abs[j], -1, 1, 0, 0);
616 db9->dev[i].absmin[db9_abs[j]] = -1; 639 else
617 db9->dev[i].absmax[db9_abs[j]] = 1; 640 input_set_abs_params(input_dev, db9_abs[j], 1, 255, 0, 0);
618 } else {
619 db9->dev[i].absmin[db9_abs[j]] = 1;
620 db9->dev[i].absmax[db9_abs[j]] = 255;
621 db9->dev[i].absflat[db9_abs[j]] = 0;
622 }
623 } 641 }
624 input_register_device(db9->dev + i); 642
625 printk(KERN_INFO "input: %s on %s\n", db9->dev[i].name, db9->pd->port->name); 643 input_register_device(input_dev);
626 } 644 }
627 645
646 parport_put_port(pp);
628 return db9; 647 return db9;
648
649 err_free_devs:
650 while (--i >= 0)
651 input_unregister_device(db9->dev[i]);
652 kfree(db9);
653 err_unreg_pardev:
654 parport_unregister_device(pd);
655 err_put_pp:
656 parport_put_port(pp);
657 err_out:
658 return ERR_PTR(err);
659}
660
661static void __exit db9_remove(struct db9 *db9)
662{
663 int i;
664
665 for (i = 0; i < min(db9_modes[db9->mode].n_pads, DB9_MAX_DEVICES); i++)
666 input_unregister_device(db9->dev[i]);
667 parport_unregister_device(db9->pd);
668 kfree(db9);
629} 669}
630 670
631static int __init db9_init(void) 671static int __init db9_init(void)
632{ 672{
633 db9_base[0] = db9_probe(db9, db9_nargs); 673 int i;
634 db9_base[1] = db9_probe(db9_2, db9_nargs_2); 674 int have_dev = 0;
635 db9_base[2] = db9_probe(db9_3, db9_nargs_3); 675 int err = 0;
676
677 for (i = 0; i < DB9_MAX_PORTS; i++) {
678 if (db9[i].nargs == 0 || db9[i].args[DB9_ARG_PARPORT] < 0)
679 continue;
680
681 if (db9[i].nargs < 2) {
682 printk(KERN_ERR "db9.c: Device type must be specified.\n");
683 err = -EINVAL;
684 break;
685 }
686
687 db9_base[i] = db9_probe(db9[i].args[DB9_ARG_PARPORT],
688 db9[i].args[DB9_ARG_MODE]);
689 if (IS_ERR(db9_base[i])) {
690 err = PTR_ERR(db9_base[i]);
691 break;
692 }
693
694 have_dev = 1;
695 }
636 696
637 if (db9_base[0] || db9_base[1] || db9_base[2]) 697 if (err) {
638 return 0; 698 while (--i >= 0)
699 db9_remove(db9_base[i]);
700 return err;
701 }
639 702
640 return -ENODEV; 703 return have_dev ? 0 : -ENODEV;
641} 704}
642 705
643static void __exit db9_exit(void) 706static void __exit db9_exit(void)
644{ 707{
645 int i, j; 708 int i;
646 709
647 for (i = 0; i < 3; i++) 710 for (i = 0; i < DB9_MAX_PORTS; i++)
648 if (db9_base[i]) { 711 if (db9_base[i])
649 for (j = 0; j < min(db9_max_pads[db9_base[i]->mode], DB9_MAX_DEVICES); j++) 712 db9_remove(db9_base[i]);
650 input_unregister_device(db9_base[i]->dev + j);
651 parport_unregister_device(db9_base[i]->pd);
652 }
653} 713}
654 714
655module_init(db9_init); 715module_init(db9_init);