2 * NES, SNES, N64, MultiSystem, PSX gamepad driver for Linux
4 * Copyright (c) 1999-2004 Vojtech Pavlik <vojtech@suse.cz>
5 * Copyright (c) 2004 Peter Nelson <rufus-kernel@hackish.org>
7 * Based on the work of:
8 * Andree Borrmann John Dahlstrom
9 * David Kuder Nathan Hand
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 * Should you need to contact me, the author, you can do so either by
29 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
30 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
33 #include <linux/kernel.h>
34 #include <linux/delay.h>
35 #include <linux/module.h>
36 #include <linux/moduleparam.h>
37 #include <linux/init.h>
38 #include <linux/parport.h>
39 #include <linux/input.h>
40 #include <linux/mutex.h>
42 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
43 MODULE_DESCRIPTION("NES, SNES, N64, MultiSystem, PSX gamepad driver");
44 MODULE_LICENSE("GPL");
46 #define GC_MAX_PORTS 3
47 #define GC_MAX_DEVICES 5
50 int args[GC_MAX_DEVICES + 1];
54 static struct gc_config gc[GC_MAX_PORTS] __initdata;
56 module_param_array_named(map, gc[0].args, int, &gc[0].nargs, 0);
57 MODULE_PARM_DESC(map, "Describes first set of devices (<parport#>,<pad1>,<pad2>,..<pad5>)");
58 module_param_array_named(map2, gc[1].args, int, &gc[1].nargs, 0);
59 MODULE_PARM_DESC(map2, "Describes second set of devices");
60 module_param_array_named(map3, gc[2].args, int, &gc[2].nargs, 0);
61 MODULE_PARM_DESC(map3, "Describes third set of devices");
63 /* see also gs_psx_delay parameter in PSX support section */
73 #define GC_SNESMOUSE 9
77 #define GC_REFRESH_TIME HZ/100
81 struct input_dev *dev[GC_MAX_DEVICES];
82 struct timer_list timer;
83 unsigned char pads[GC_MAX + 1];
86 char phys[GC_MAX_DEVICES][32];
89 static struct gc *gc_base[3];
91 static int gc_status_bit[] = { 0x40, 0x80, 0x20, 0x10, 0x08 };
93 static char *gc_names[] = { NULL, "SNES pad", "NES pad", "NES FourPort", "Multisystem joystick",
94 "Multisystem 2-button joystick", "N64 controller", "PSX controller",
95 "PSX DDR controller", "SNES mouse" };
100 static unsigned char gc_n64_bytes[] = { 0, 1, 13, 15, 14, 12, 10, 11, 2, 3 };
101 static short gc_n64_btn[] = { BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_TL, BTN_TR, BTN_TRIGGER, BTN_START };
103 #define GC_N64_LENGTH 32 /* N64 bit length, not including stop bit */
104 #define GC_N64_REQUEST_LENGTH 37 /* transmit request sequence is 9 bits long */
105 #define GC_N64_DELAY 133 /* delay between transmit request, and response ready (us) */
106 #define GC_N64_REQUEST 0x1dd1111111ULL /* the request data command (encoded for 000000011) */
107 #define GC_N64_DWS 3 /* delay between write segments (required for sound playback because of ISA DMA) */
108 /* GC_N64_DWS > 24 is known to fail */
109 #define GC_N64_POWER_W 0xe2 /* power during write (transmit request) */
110 #define GC_N64_POWER_R 0xfd /* power during read */
111 #define GC_N64_OUT 0x1d /* output bits to the 4 pads */
112 /* Reading the main axes of any N64 pad is known to fail if the corresponding bit */
113 /* in GC_N64_OUT is pulled low on the output port (by any routine) for more */
115 #define GC_N64_CLOCK 0x02 /* clock bits for read */
118 * gc_n64_read_packet() reads an N64 packet.
119 * Each pad uses one bit per byte. So all pads connected to this port are read in parallel.
122 static void gc_n64_read_packet(struct gc *gc, unsigned char *data)
128 * Request the pad to transmit data
131 local_irq_save(flags);
132 for (i = 0; i < GC_N64_REQUEST_LENGTH; i++) {
133 parport_write_data(gc->pd->port, GC_N64_POWER_W | ((GC_N64_REQUEST >> i) & 1 ? GC_N64_OUT : 0));
136 local_irq_restore(flags);
139 * Wait for the pad response to be loaded into the 33-bit register of the adapter
142 udelay(GC_N64_DELAY);
145 * Grab data (ignoring the last bit, which is a stop bit)
148 for (i = 0; i < GC_N64_LENGTH; i++) {
149 parport_write_data(gc->pd->port, GC_N64_POWER_R);
150 data[i] = parport_read_status(gc->pd->port);
151 parport_write_data(gc->pd->port, GC_N64_POWER_R | GC_N64_CLOCK);
155 * We must wait 200 ms here for the controller to reinitialize before the next read request.
156 * No worries as long as gc_read is polled less frequently than this.
161 static void gc_n64_process_packet(struct gc *gc)
163 unsigned char data[GC_N64_LENGTH];
165 struct input_dev *dev;
168 gc_n64_read_packet(gc, data);
170 for (i = 0; i < GC_MAX_DEVICES; i++) {
176 s = gc_status_bit[i];
178 if (s & gc->pads[GC_N64] & ~(data[8] | data[9])) {
180 axes[0] = axes[1] = 0;
182 for (j = 0; j < 8; j++) {
183 if (data[23 - j] & s)
185 if (data[31 - j] & s)
189 input_report_abs(dev, ABS_X, axes[0]);
190 input_report_abs(dev, ABS_Y, -axes[1]);
192 input_report_abs(dev, ABS_HAT0X, !(s & data[6]) - !(s & data[7]));
193 input_report_abs(dev, ABS_HAT0Y, !(s & data[4]) - !(s & data[5]));
195 for (j = 0; j < 10; j++)
196 input_report_key(dev, gc_n64_btn[j], s & data[gc_n64_bytes[j]]);
207 #define GC_NES_DELAY 6 /* Delay between bits - 6us */
208 #define GC_NES_LENGTH 8 /* The NES pads use 8 bits of data */
209 #define GC_SNES_LENGTH 12 /* The SNES true length is 16, but the
210 last 4 bits are unused */
211 #define GC_SNESMOUSE_LENGTH 32 /* The SNES mouse uses 32 bits, the first
212 16 bits are equivalent to a gamepad */
214 #define GC_NES_POWER 0xfc
215 #define GC_NES_CLOCK 0x01
216 #define GC_NES_LATCH 0x02
218 static unsigned char gc_nes_bytes[] = { 0, 1, 2, 3 };
219 static unsigned char gc_snes_bytes[] = { 8, 0, 2, 3, 9, 1, 10, 11 };
220 static short gc_snes_btn[] = { BTN_A, BTN_B, BTN_SELECT, BTN_START, BTN_X, BTN_Y, BTN_TL, BTN_TR };
223 * gc_nes_read_packet() reads a NES/SNES packet.
224 * Each pad uses one bit per byte. So all pads connected to
225 * this port are read in parallel.
228 static void gc_nes_read_packet(struct gc *gc, int length, unsigned char *data)
232 parport_write_data(gc->pd->port, GC_NES_POWER | GC_NES_CLOCK | GC_NES_LATCH);
233 udelay(GC_NES_DELAY * 2);
234 parport_write_data(gc->pd->port, GC_NES_POWER | GC_NES_CLOCK);
236 for (i = 0; i < length; i++) {
237 udelay(GC_NES_DELAY);
238 parport_write_data(gc->pd->port, GC_NES_POWER);
239 data[i] = parport_read_status(gc->pd->port) ^ 0x7f;
240 udelay(GC_NES_DELAY);
241 parport_write_data(gc->pd->port, GC_NES_POWER | GC_NES_CLOCK);
245 static void gc_nes_process_packet(struct gc *gc)
247 unsigned char data[GC_SNESMOUSE_LENGTH];
248 struct input_dev *dev;
252 len = gc->pads[GC_SNESMOUSE] ? GC_SNESMOUSE_LENGTH :
253 (gc->pads[GC_SNES] ? GC_SNES_LENGTH : GC_NES_LENGTH);
255 gc_nes_read_packet(gc, len, data);
257 for (i = 0; i < GC_MAX_DEVICES; i++) {
263 s = gc_status_bit[i];
265 if (s & (gc->pads[GC_NES] | gc->pads[GC_SNES])) {
266 input_report_abs(dev, ABS_X, !(s & data[6]) - !(s & data[7]));
267 input_report_abs(dev, ABS_Y, !(s & data[4]) - !(s & data[5]));
270 if (s & gc->pads[GC_NES])
271 for (j = 0; j < 4; j++)
272 input_report_key(dev, gc_snes_btn[j], s & data[gc_nes_bytes[j]]);
274 if (s & gc->pads[GC_SNES])
275 for (j = 0; j < 8; j++)
276 input_report_key(dev, gc_snes_btn[j], s & data[gc_snes_bytes[j]]);
278 if (s & gc->pads[GC_SNESMOUSE]) {
280 * The 4 unused bits from SNES controllers appear to be ID bits
281 * so use them to make sure iwe are dealing with a mouse.
282 * gamepad is connected. This is important since
283 * my SNES gamepad sends 1's for bits 16-31, which
284 * cause the mouse pointer to quickly move to the
285 * upper left corner of the screen.
287 if (!(s & data[12]) && !(s & data[13]) &&
288 !(s & data[14]) && (s & data[15])) {
289 input_report_key(dev, BTN_LEFT, s & data[9]);
290 input_report_key(dev, BTN_RIGHT, s & data[8]);
293 for (j = 0; j < 7; j++) {
295 if (data[25 + j] & s)
299 if (data[17 + j] & s)
306 input_report_rel(dev, REL_X, x_rel);
312 input_report_rel(dev, REL_Y, y_rel);
321 * Multisystem joystick support
324 #define GC_MULTI_LENGTH 5 /* Multi system joystick packet length is 5 */
325 #define GC_MULTI2_LENGTH 6 /* One more bit for one more button */
328 * gc_multi_read_packet() reads a Multisystem joystick packet.
331 static void gc_multi_read_packet(struct gc *gc, int length, unsigned char *data)
335 for (i = 0; i < length; i++) {
336 parport_write_data(gc->pd->port, ~(1 << i));
337 data[i] = parport_read_status(gc->pd->port) ^ 0x7f;
341 static void gc_multi_process_packet(struct gc *gc)
343 unsigned char data[GC_MULTI2_LENGTH];
344 struct input_dev *dev;
347 gc_multi_read_packet(gc, gc->pads[GC_MULTI2] ? GC_MULTI2_LENGTH : GC_MULTI_LENGTH, data);
349 for (i = 0; i < GC_MAX_DEVICES; i++) {
355 s = gc_status_bit[i];
357 if (s & (gc->pads[GC_MULTI] | gc->pads[GC_MULTI2])) {
358 input_report_abs(dev, ABS_X, !(s & data[2]) - !(s & data[3]));
359 input_report_abs(dev, ABS_Y, !(s & data[0]) - !(s & data[1]));
360 input_report_key(dev, BTN_TRIGGER, s & data[4]);
363 if (s & gc->pads[GC_MULTI2])
364 input_report_key(dev, BTN_THUMB, s & data[5]);
373 * See documentation at:
374 * http://www.dim.com/~mackys/psxmemcard/ps-eng2.txt
375 * http://www.gamesx.com/controldata/psxcont/psxcont.htm
376 * ftp://milano.usal.es/pablo/
380 #define GC_PSX_DELAY 25 /* 25 usec */
381 #define GC_PSX_LENGTH 8 /* talk to the controller in bits */
382 #define GC_PSX_BYTES 6 /* the maximum number of bytes to read off the controller */
384 #define GC_PSX_MOUSE 1 /* Mouse */
385 #define GC_PSX_NEGCON 2 /* NegCon */
386 #define GC_PSX_NORMAL 4 /* Digital / Analog or Rumble in Digital mode */
387 #define GC_PSX_ANALOG 5 /* Analog in Analog mode / Rumble in Green mode */
388 #define GC_PSX_RUMBLE 7 /* Rumble in Red mode */
390 #define GC_PSX_CLOCK 0x04 /* Pin 4 */
391 #define GC_PSX_COMMAND 0x01 /* Pin 2 */
392 #define GC_PSX_POWER 0xf8 /* Pins 5-9 */
393 #define GC_PSX_SELECT 0x02 /* Pin 3 */
395 #define GC_PSX_ID(x) ((x) >> 4) /* High nibble is device type */
396 #define GC_PSX_LEN(x) (((x) & 0xf) << 1) /* Low nibble is length in bytes/2 */
398 static int gc_psx_delay = GC_PSX_DELAY;
399 module_param_named(psx_delay, gc_psx_delay, uint, 0);
400 MODULE_PARM_DESC(psx_delay, "Delay when accessing Sony PSX controller (usecs)");
402 static short gc_psx_abs[] = { ABS_X, ABS_Y, ABS_RX, ABS_RY, ABS_HAT0X, ABS_HAT0Y };
403 static short gc_psx_btn[] = { BTN_TL, BTN_TR, BTN_TL2, BTN_TR2, BTN_A, BTN_B, BTN_X, BTN_Y,
404 BTN_START, BTN_SELECT, BTN_THUMBL, BTN_THUMBR };
405 static short gc_psx_ddr_btn[] = { BTN_0, BTN_1, BTN_2, BTN_3 };
408 * gc_psx_command() writes 8bit command and reads 8bit data from
412 static void gc_psx_command(struct gc *gc, int b, unsigned char data[GC_MAX_DEVICES])
416 for (i = 0; i < GC_MAX_DEVICES; i++)
419 for (i = 0; i < GC_PSX_LENGTH; i++, b >>= 1) {
420 cmd = (b & 1) ? GC_PSX_COMMAND : 0;
421 parport_write_data(gc->pd->port, cmd | GC_PSX_POWER);
422 udelay(gc_psx_delay);
423 read = parport_read_status(gc->pd->port) ^ 0x80;
424 for (j = 0; j < GC_MAX_DEVICES; j++)
425 data[j] |= (read & gc_status_bit[j] & (gc->pads[GC_PSX] | gc->pads[GC_DDR])) ? (1 << i) : 0;
426 parport_write_data(gc->pd->port, cmd | GC_PSX_CLOCK | GC_PSX_POWER);
427 udelay(gc_psx_delay);
432 * gc_psx_read_packet() reads a whole psx packet and returns
433 * device identifier code.
436 static void gc_psx_read_packet(struct gc *gc, unsigned char data[GC_MAX_DEVICES][GC_PSX_BYTES],
437 unsigned char id[GC_MAX_DEVICES])
439 int i, j, max_len = 0;
441 unsigned char data2[GC_MAX_DEVICES];
443 parport_write_data(gc->pd->port, GC_PSX_CLOCK | GC_PSX_SELECT | GC_PSX_POWER); /* Select pad */
444 udelay(gc_psx_delay);
445 parport_write_data(gc->pd->port, GC_PSX_CLOCK | GC_PSX_POWER); /* Deselect, begin command */
446 udelay(gc_psx_delay);
448 local_irq_save(flags);
450 gc_psx_command(gc, 0x01, data2); /* Access pad */
451 gc_psx_command(gc, 0x42, id); /* Get device ids */
452 gc_psx_command(gc, 0, data2); /* Dump status */
454 for (i =0; i < GC_MAX_DEVICES; i++) /* Find the longest pad */
455 if((gc_status_bit[i] & (gc->pads[GC_PSX] | gc->pads[GC_DDR]))
456 && (GC_PSX_LEN(id[i]) > max_len)
457 && (GC_PSX_LEN(id[i]) <= GC_PSX_BYTES))
458 max_len = GC_PSX_LEN(id[i]);
460 for (i = 0; i < max_len; i++) { /* Read in all the data */
461 gc_psx_command(gc, 0, data2);
462 for (j = 0; j < GC_MAX_DEVICES; j++)
463 data[j][i] = data2[j];
466 local_irq_restore(flags);
468 parport_write_data(gc->pd->port, GC_PSX_CLOCK | GC_PSX_SELECT | GC_PSX_POWER);
470 for(i = 0; i < GC_MAX_DEVICES; i++) /* Set id's to the real value */
471 id[i] = GC_PSX_ID(id[i]);
474 static void gc_psx_process_packet(struct gc *gc)
476 unsigned char data[GC_MAX_DEVICES][GC_PSX_BYTES];
477 unsigned char id[GC_MAX_DEVICES];
478 struct input_dev *dev;
481 gc_psx_read_packet(gc, data, id);
483 for (i = 0; i < GC_MAX_DEVICES; i++) {
493 input_report_key(dev, BTN_THUMBL, ~data[i][0] & 0x04);
494 input_report_key(dev, BTN_THUMBR, ~data[i][0] & 0x02);
499 if (gc->pads[GC_DDR] & gc_status_bit[i]) {
500 for(j = 0; j < 4; j++)
501 input_report_key(dev, gc_psx_ddr_btn[j], ~data[i][0] & (0x10 << j));
503 for (j = 0; j < 4; j++)
504 input_report_abs(dev, gc_psx_abs[j + 2], data[i][j + 2]);
506 input_report_abs(dev, ABS_X, 128 + !(data[i][0] & 0x20) * 127 - !(data[i][0] & 0x80) * 128);
507 input_report_abs(dev, ABS_Y, 128 + !(data[i][0] & 0x40) * 127 - !(data[i][0] & 0x10) * 128);
510 for (j = 0; j < 8; j++)
511 input_report_key(dev, gc_psx_btn[j], ~data[i][1] & (1 << j));
513 input_report_key(dev, BTN_START, ~data[i][0] & 0x08);
514 input_report_key(dev, BTN_SELECT, ~data[i][0] & 0x01);
521 if (gc->pads[GC_DDR] & gc_status_bit[i]) {
522 for(j = 0; j < 4; j++)
523 input_report_key(dev, gc_psx_ddr_btn[j], ~data[i][0] & (0x10 << j));
525 input_report_abs(dev, ABS_X, 128 + !(data[i][0] & 0x20) * 127 - !(data[i][0] & 0x80) * 128);
526 input_report_abs(dev, ABS_Y, 128 + !(data[i][0] & 0x40) * 127 - !(data[i][0] & 0x10) * 128);
528 /* for some reason if the extra axes are left unset they drift */
529 /* for (j = 0; j < 4; j++)
530 input_report_abs(dev, gc_psx_abs[j + 2], 128);
531 * This needs to be debugged properly,
532 * maybe fuzz processing needs to be done in input_sync()
537 for (j = 0; j < 8; j++)
538 input_report_key(dev, gc_psx_btn[j], ~data[i][1] & (1 << j));
540 input_report_key(dev, BTN_START, ~data[i][0] & 0x08);
541 input_report_key(dev, BTN_SELECT, ~data[i][0] & 0x01);
547 case 0: /* not a pad, ignore */
554 * gc_timer() initiates reads of console pads data.
557 static void gc_timer(unsigned long private)
559 struct gc *gc = (void *) private;
562 * N64 pads - must be read first, any read confuses them for 200 us
565 if (gc->pads[GC_N64])
566 gc_n64_process_packet(gc);
569 * NES and SNES pads or mouse
572 if (gc->pads[GC_NES] || gc->pads[GC_SNES] || gc->pads[GC_SNESMOUSE])
573 gc_nes_process_packet(gc);
576 * Multi and Multi2 joysticks
579 if (gc->pads[GC_MULTI] || gc->pads[GC_MULTI2])
580 gc_multi_process_packet(gc);
586 if (gc->pads[GC_PSX] || gc->pads[GC_DDR])
587 gc_psx_process_packet(gc);
589 mod_timer(&gc->timer, jiffies + GC_REFRESH_TIME);
592 static int gc_open(struct input_dev *dev)
594 struct gc *gc = input_get_drvdata(dev);
597 err = mutex_lock_interruptible(&gc->mutex);
602 parport_claim(gc->pd);
603 parport_write_control(gc->pd->port, 0x04);
604 mod_timer(&gc->timer, jiffies + GC_REFRESH_TIME);
607 mutex_unlock(&gc->mutex);
611 static void gc_close(struct input_dev *dev)
613 struct gc *gc = input_get_drvdata(dev);
615 mutex_lock(&gc->mutex);
617 del_timer_sync(&gc->timer);
618 parport_write_control(gc->pd->port, 0x00);
619 parport_release(gc->pd);
621 mutex_unlock(&gc->mutex);
624 static int __init gc_setup_pad(struct gc *gc, int idx, int pad_type)
626 struct input_dev *input_dev;
632 if (pad_type < 1 || pad_type > GC_MAX) {
633 printk(KERN_WARNING "gamecon.c: Pad type %d unknown\n", pad_type);
637 gc->dev[idx] = input_dev = input_allocate_device();
639 printk(KERN_ERR "gamecon.c: Not enough memory for input device\n");
643 input_dev->name = gc_names[pad_type];
644 input_dev->phys = gc->phys[idx];
645 input_dev->id.bustype = BUS_PARPORT;
646 input_dev->id.vendor = 0x0001;
647 input_dev->id.product = pad_type;
648 input_dev->id.version = 0x0100;
650 input_set_drvdata(input_dev, gc);
652 input_dev->open = gc_open;
653 input_dev->close = gc_close;
655 if (pad_type != GC_SNESMOUSE) {
656 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
658 for (i = 0; i < 2; i++)
659 input_set_abs_params(input_dev, ABS_X + i, -1, 1, 0, 0);
661 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
663 gc->pads[0] |= gc_status_bit[idx];
664 gc->pads[pad_type] |= gc_status_bit[idx];
669 for (i = 0; i < 10; i++)
670 set_bit(gc_n64_btn[i], input_dev->keybit);
672 for (i = 0; i < 2; i++) {
673 input_set_abs_params(input_dev, ABS_X + i, -127, 126, 0, 2);
674 input_set_abs_params(input_dev, ABS_HAT0X + i, -1, 1, 0, 0);
680 set_bit(BTN_LEFT, input_dev->keybit);
681 set_bit(BTN_RIGHT, input_dev->keybit);
682 set_bit(REL_X, input_dev->relbit);
683 set_bit(REL_Y, input_dev->relbit);
687 for (i = 4; i < 8; i++)
688 set_bit(gc_snes_btn[i], input_dev->keybit);
690 for (i = 0; i < 4; i++)
691 set_bit(gc_snes_btn[i], input_dev->keybit);
695 set_bit(BTN_THUMB, input_dev->keybit);
697 set_bit(BTN_TRIGGER, input_dev->keybit);
701 for (i = 0; i < 6; i++)
702 input_set_abs_params(input_dev, gc_psx_abs[i], 4, 252, 0, 2);
703 for (i = 0; i < 12; i++)
704 set_bit(gc_psx_btn[i], input_dev->keybit);
709 for (i = 0; i < 4; i++)
710 set_bit(gc_psx_ddr_btn[i], input_dev->keybit);
711 for (i = 0; i < 12; i++)
712 set_bit(gc_psx_btn[i], input_dev->keybit);
720 static struct gc __init *gc_probe(int parport, int *pads, int n_pads)
724 struct pardevice *pd;
728 pp = parport_find_number(parport);
730 printk(KERN_ERR "gamecon.c: no such parport\n");
735 pd = parport_register_device(pp, "gamecon", NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL);
737 printk(KERN_ERR "gamecon.c: parport busy already - lp.o loaded?\n");
742 gc = kzalloc(sizeof(struct gc), GFP_KERNEL);
744 printk(KERN_ERR "gamecon.c: Not enough memory\n");
746 goto err_unreg_pardev;
749 mutex_init(&gc->mutex);
751 init_timer(&gc->timer);
752 gc->timer.data = (long) gc;
753 gc->timer.function = gc_timer;
755 for (i = 0; i < n_pads && i < GC_MAX_DEVICES; i++) {
759 snprintf(gc->phys[i], sizeof(gc->phys[i]),
760 "%s/input%d", gc->pd->port->name, i);
761 err = gc_setup_pad(gc, i, pads[i]);
765 err = input_register_device(gc->dev[i]);
771 printk(KERN_ERR "gamecon.c: No valid devices specified\n");
776 parport_put_port(pp);
780 input_free_device(gc->dev[i]);
784 input_unregister_device(gc->dev[i]);
788 parport_unregister_device(pd);
790 parport_put_port(pp);
795 static void gc_remove(struct gc *gc)
799 for (i = 0; i < GC_MAX_DEVICES; i++)
801 input_unregister_device(gc->dev[i]);
802 parport_unregister_device(gc->pd);
806 static int __init gc_init(void)
812 for (i = 0; i < GC_MAX_PORTS; i++) {
813 if (gc[i].nargs == 0 || gc[i].args[0] < 0)
816 if (gc[i].nargs < 2) {
817 printk(KERN_ERR "gamecon.c: at least one device must be specified\n");
822 gc_base[i] = gc_probe(gc[i].args[0], gc[i].args + 1, gc[i].nargs - 1);
823 if (IS_ERR(gc_base[i])) {
824 err = PTR_ERR(gc_base[i]);
834 gc_remove(gc_base[i]);
838 return have_dev ? 0 : -ENODEV;
841 static void __exit gc_exit(void)
845 for (i = 0; i < GC_MAX_PORTS; i++)
847 gc_remove(gc_base[i]);
850 module_init(gc_init);
851 module_exit(gc_exit);