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 __obsolete_setup("gc=");
64 __obsolete_setup("gc_2=");
65 __obsolete_setup("gc_3=");
67 /* see also gs_psx_delay parameter in PSX support section */
77 #define GC_SNESMOUSE 9
81 #define GC_REFRESH_TIME HZ/100
85 struct input_dev
*dev
[GC_MAX_DEVICES
];
86 struct timer_list timer
;
87 unsigned char pads
[GC_MAX
+ 1];
90 char phys
[GC_MAX_DEVICES
][32];
93 static struct gc
*gc_base
[3];
95 static int gc_status_bit
[] = { 0x40, 0x80, 0x20, 0x10, 0x08 };
97 static char *gc_names
[] = { NULL
, "SNES pad", "NES pad", "NES FourPort", "Multisystem joystick",
98 "Multisystem 2-button joystick", "N64 controller", "PSX controller",
99 "PSX DDR controller", "SNES mouse" };
104 static unsigned char gc_n64_bytes
[] = { 0, 1, 13, 15, 14, 12, 10, 11, 2, 3 };
105 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
};
107 #define GC_N64_LENGTH 32 /* N64 bit length, not including stop bit */
108 #define GC_N64_REQUEST_LENGTH 37 /* transmit request sequence is 9 bits long */
109 #define GC_N64_DELAY 133 /* delay between transmit request, and response ready (us) */
110 #define GC_N64_REQUEST 0x1dd1111111ULL /* the request data command (encoded for 000000011) */
111 #define GC_N64_DWS 3 /* delay between write segments (required for sound playback because of ISA DMA) */
112 /* GC_N64_DWS > 24 is known to fail */
113 #define GC_N64_POWER_W 0xe2 /* power during write (transmit request) */
114 #define GC_N64_POWER_R 0xfd /* power during read */
115 #define GC_N64_OUT 0x1d /* output bits to the 4 pads */
116 /* Reading the main axes of any N64 pad is known to fail if the corresponding bit */
117 /* in GC_N64_OUT is pulled low on the output port (by any routine) for more */
119 #define GC_N64_CLOCK 0x02 /* clock bits for read */
122 * gc_n64_read_packet() reads an N64 packet.
123 * Each pad uses one bit per byte. So all pads connected to this port are read in parallel.
126 static void gc_n64_read_packet(struct gc
*gc
, unsigned char *data
)
132 * Request the pad to transmit data
135 local_irq_save(flags
);
136 for (i
= 0; i
< GC_N64_REQUEST_LENGTH
; i
++) {
137 parport_write_data(gc
->pd
->port
, GC_N64_POWER_W
| ((GC_N64_REQUEST
>> i
) & 1 ? GC_N64_OUT
: 0));
140 local_irq_restore(flags
);
143 * Wait for the pad response to be loaded into the 33-bit register of the adapter
146 udelay(GC_N64_DELAY
);
149 * Grab data (ignoring the last bit, which is a stop bit)
152 for (i
= 0; i
< GC_N64_LENGTH
; i
++) {
153 parport_write_data(gc
->pd
->port
, GC_N64_POWER_R
);
154 data
[i
] = parport_read_status(gc
->pd
->port
);
155 parport_write_data(gc
->pd
->port
, GC_N64_POWER_R
| GC_N64_CLOCK
);
159 * We must wait 200 ms here for the controller to reinitialize before the next read request.
160 * No worries as long as gc_read is polled less frequently than this.
165 static void gc_n64_process_packet(struct gc
*gc
)
167 unsigned char data
[GC_N64_LENGTH
];
169 struct input_dev
*dev
;
172 gc_n64_read_packet(gc
, data
);
174 for (i
= 0; i
< GC_MAX_DEVICES
; i
++) {
180 s
= gc_status_bit
[i
];
182 if (s
& gc
->pads
[GC_N64
] & ~(data
[8] | data
[9])) {
184 axes
[0] = axes
[1] = 0;
186 for (j
= 0; j
< 8; j
++) {
187 if (data
[23 - j
] & s
)
189 if (data
[31 - j
] & s
)
193 input_report_abs(dev
, ABS_X
, axes
[0]);
194 input_report_abs(dev
, ABS_Y
, -axes
[1]);
196 input_report_abs(dev
, ABS_HAT0X
, !(s
& data
[6]) - !(s
& data
[7]));
197 input_report_abs(dev
, ABS_HAT0Y
, !(s
& data
[4]) - !(s
& data
[5]));
199 for (j
= 0; j
< 10; j
++)
200 input_report_key(dev
, gc_n64_btn
[j
], s
& data
[gc_n64_bytes
[j
]]);
211 #define GC_NES_DELAY 6 /* Delay between bits - 6us */
212 #define GC_NES_LENGTH 8 /* The NES pads use 8 bits of data */
213 #define GC_SNES_LENGTH 12 /* The SNES true length is 16, but the
214 last 4 bits are unused */
215 #define GC_SNESMOUSE_LENGTH 32 /* The SNES mouse uses 32 bits, the first
216 16 bits are equivalent to a gamepad */
218 #define GC_NES_POWER 0xfc
219 #define GC_NES_CLOCK 0x01
220 #define GC_NES_LATCH 0x02
222 static unsigned char gc_nes_bytes
[] = { 0, 1, 2, 3 };
223 static unsigned char gc_snes_bytes
[] = { 8, 0, 2, 3, 9, 1, 10, 11 };
224 static short gc_snes_btn
[] = { BTN_A
, BTN_B
, BTN_SELECT
, BTN_START
, BTN_X
, BTN_Y
, BTN_TL
, BTN_TR
};
227 * gc_nes_read_packet() reads a NES/SNES packet.
228 * Each pad uses one bit per byte. So all pads connected to
229 * this port are read in parallel.
232 static void gc_nes_read_packet(struct gc
*gc
, int length
, unsigned char *data
)
236 parport_write_data(gc
->pd
->port
, GC_NES_POWER
| GC_NES_CLOCK
| GC_NES_LATCH
);
237 udelay(GC_NES_DELAY
* 2);
238 parport_write_data(gc
->pd
->port
, GC_NES_POWER
| GC_NES_CLOCK
);
240 for (i
= 0; i
< length
; i
++) {
241 udelay(GC_NES_DELAY
);
242 parport_write_data(gc
->pd
->port
, GC_NES_POWER
);
243 data
[i
] = parport_read_status(gc
->pd
->port
) ^ 0x7f;
244 udelay(GC_NES_DELAY
);
245 parport_write_data(gc
->pd
->port
, GC_NES_POWER
| GC_NES_CLOCK
);
249 static void gc_nes_process_packet(struct gc
*gc
)
251 unsigned char data
[GC_SNESMOUSE_LENGTH
];
252 struct input_dev
*dev
;
256 len
= gc
->pads
[GC_SNESMOUSE
] ? GC_SNESMOUSE_LENGTH
:
257 (gc
->pads
[GC_SNES
] ? GC_SNES_LENGTH
: GC_NES_LENGTH
);
259 gc_nes_read_packet(gc
, len
, data
);
261 for (i
= 0; i
< GC_MAX_DEVICES
; i
++) {
267 s
= gc_status_bit
[i
];
269 if (s
& (gc
->pads
[GC_NES
] | gc
->pads
[GC_SNES
])) {
270 input_report_abs(dev
, ABS_X
, !(s
& data
[6]) - !(s
& data
[7]));
271 input_report_abs(dev
, ABS_Y
, !(s
& data
[4]) - !(s
& data
[5]));
274 if (s
& gc
->pads
[GC_NES
])
275 for (j
= 0; j
< 4; j
++)
276 input_report_key(dev
, gc_snes_btn
[j
], s
& data
[gc_nes_bytes
[j
]]);
278 if (s
& gc
->pads
[GC_SNES
])
279 for (j
= 0; j
< 8; j
++)
280 input_report_key(dev
, gc_snes_btn
[j
], s
& data
[gc_snes_bytes
[j
]]);
282 if (s
& gc
->pads
[GC_SNESMOUSE
]) {
284 * The 4 unused bits from SNES controllers appear to be ID bits
285 * so use them to make sure iwe are dealing with a mouse.
286 * gamepad is connected. This is important since
287 * my SNES gamepad sends 1's for bits 16-31, which
288 * cause the mouse pointer to quickly move to the
289 * upper left corner of the screen.
291 if (!(s
& data
[12]) && !(s
& data
[13]) &&
292 !(s
& data
[14]) && (s
& data
[15])) {
293 input_report_key(dev
, BTN_LEFT
, s
& data
[9]);
294 input_report_key(dev
, BTN_RIGHT
, s
& data
[8]);
297 for (j
= 0; j
< 7; j
++) {
299 if (data
[25 + j
] & s
)
303 if (data
[17 + j
] & s
)
310 input_report_rel(dev
, REL_X
, x_rel
);
316 input_report_rel(dev
, REL_Y
, y_rel
);
325 * Multisystem joystick support
328 #define GC_MULTI_LENGTH 5 /* Multi system joystick packet length is 5 */
329 #define GC_MULTI2_LENGTH 6 /* One more bit for one more button */
332 * gc_multi_read_packet() reads a Multisystem joystick packet.
335 static void gc_multi_read_packet(struct gc
*gc
, int length
, unsigned char *data
)
339 for (i
= 0; i
< length
; i
++) {
340 parport_write_data(gc
->pd
->port
, ~(1 << i
));
341 data
[i
] = parport_read_status(gc
->pd
->port
) ^ 0x7f;
345 static void gc_multi_process_packet(struct gc
*gc
)
347 unsigned char data
[GC_MULTI2_LENGTH
];
348 struct input_dev
*dev
;
351 gc_multi_read_packet(gc
, gc
->pads
[GC_MULTI2
] ? GC_MULTI2_LENGTH
: GC_MULTI_LENGTH
, data
);
353 for (i
= 0; i
< GC_MAX_DEVICES
; i
++) {
359 s
= gc_status_bit
[i
];
361 if (s
& (gc
->pads
[GC_MULTI
] | gc
->pads
[GC_MULTI2
])) {
362 input_report_abs(dev
, ABS_X
, !(s
& data
[2]) - !(s
& data
[3]));
363 input_report_abs(dev
, ABS_Y
, !(s
& data
[0]) - !(s
& data
[1]));
364 input_report_key(dev
, BTN_TRIGGER
, s
& data
[4]);
367 if (s
& gc
->pads
[GC_MULTI2
])
368 input_report_key(dev
, BTN_THUMB
, s
& data
[5]);
377 * See documentation at:
378 * http://www.dim.com/~mackys/psxmemcard/ps-eng2.txt
379 * http://www.gamesx.com/controldata/psxcont/psxcont.htm
380 * ftp://milano.usal.es/pablo/
384 #define GC_PSX_DELAY 25 /* 25 usec */
385 #define GC_PSX_LENGTH 8 /* talk to the controller in bits */
386 #define GC_PSX_BYTES 6 /* the maximum number of bytes to read off the controller */
388 #define GC_PSX_MOUSE 1 /* Mouse */
389 #define GC_PSX_NEGCON 2 /* NegCon */
390 #define GC_PSX_NORMAL 4 /* Digital / Analog or Rumble in Digital mode */
391 #define GC_PSX_ANALOG 5 /* Analog in Analog mode / Rumble in Green mode */
392 #define GC_PSX_RUMBLE 7 /* Rumble in Red mode */
394 #define GC_PSX_CLOCK 0x04 /* Pin 4 */
395 #define GC_PSX_COMMAND 0x01 /* Pin 2 */
396 #define GC_PSX_POWER 0xf8 /* Pins 5-9 */
397 #define GC_PSX_SELECT 0x02 /* Pin 3 */
399 #define GC_PSX_ID(x) ((x) >> 4) /* High nibble is device type */
400 #define GC_PSX_LEN(x) (((x) & 0xf) << 1) /* Low nibble is length in bytes/2 */
402 static int gc_psx_delay
= GC_PSX_DELAY
;
403 module_param_named(psx_delay
, gc_psx_delay
, uint
, 0);
404 MODULE_PARM_DESC(psx_delay
, "Delay when accessing Sony PSX controller (usecs)");
406 __obsolete_setup("gc_psx_delay=");
408 static short gc_psx_abs
[] = { ABS_X
, ABS_Y
, ABS_RX
, ABS_RY
, ABS_HAT0X
, ABS_HAT0Y
};
409 static short gc_psx_btn
[] = { BTN_TL
, BTN_TR
, BTN_TL2
, BTN_TR2
, BTN_A
, BTN_B
, BTN_X
, BTN_Y
,
410 BTN_START
, BTN_SELECT
, BTN_THUMBL
, BTN_THUMBR
};
411 static short gc_psx_ddr_btn
[] = { BTN_0
, BTN_1
, BTN_2
, BTN_3
};
414 * gc_psx_command() writes 8bit command and reads 8bit data from
418 static void gc_psx_command(struct gc
*gc
, int b
, unsigned char data
[GC_MAX_DEVICES
])
422 for (i
= 0; i
< GC_MAX_DEVICES
; i
++)
425 for (i
= 0; i
< GC_PSX_LENGTH
; i
++, b
>>= 1) {
426 cmd
= (b
& 1) ? GC_PSX_COMMAND
: 0;
427 parport_write_data(gc
->pd
->port
, cmd
| GC_PSX_POWER
);
428 udelay(gc_psx_delay
);
429 read
= parport_read_status(gc
->pd
->port
) ^ 0x80;
430 for (j
= 0; j
< GC_MAX_DEVICES
; j
++)
431 data
[j
] |= (read
& gc_status_bit
[j
] & (gc
->pads
[GC_PSX
] | gc
->pads
[GC_DDR
])) ? (1 << i
) : 0;
432 parport_write_data(gc
->pd
->port
, cmd
| GC_PSX_CLOCK
| GC_PSX_POWER
);
433 udelay(gc_psx_delay
);
438 * gc_psx_read_packet() reads a whole psx packet and returns
439 * device identifier code.
442 static void gc_psx_read_packet(struct gc
*gc
, unsigned char data
[GC_MAX_DEVICES
][GC_PSX_BYTES
],
443 unsigned char id
[GC_MAX_DEVICES
])
445 int i
, j
, max_len
= 0;
447 unsigned char data2
[GC_MAX_DEVICES
];
449 parport_write_data(gc
->pd
->port
, GC_PSX_CLOCK
| GC_PSX_SELECT
| GC_PSX_POWER
); /* Select pad */
450 udelay(gc_psx_delay
);
451 parport_write_data(gc
->pd
->port
, GC_PSX_CLOCK
| GC_PSX_POWER
); /* Deselect, begin command */
452 udelay(gc_psx_delay
);
454 local_irq_save(flags
);
456 gc_psx_command(gc
, 0x01, data2
); /* Access pad */
457 gc_psx_command(gc
, 0x42, id
); /* Get device ids */
458 gc_psx_command(gc
, 0, data2
); /* Dump status */
460 for (i
=0; i
< GC_MAX_DEVICES
; i
++) /* Find the longest pad */
461 if((gc_status_bit
[i
] & (gc
->pads
[GC_PSX
] | gc
->pads
[GC_DDR
]))
462 && (GC_PSX_LEN(id
[i
]) > max_len
)
463 && (GC_PSX_LEN(id
[i
]) <= GC_PSX_BYTES
))
464 max_len
= GC_PSX_LEN(id
[i
]);
466 for (i
= 0; i
< max_len
; i
++) { /* Read in all the data */
467 gc_psx_command(gc
, 0, data2
);
468 for (j
= 0; j
< GC_MAX_DEVICES
; j
++)
469 data
[j
][i
] = data2
[j
];
472 local_irq_restore(flags
);
474 parport_write_data(gc
->pd
->port
, GC_PSX_CLOCK
| GC_PSX_SELECT
| GC_PSX_POWER
);
476 for(i
= 0; i
< GC_MAX_DEVICES
; i
++) /* Set id's to the real value */
477 id
[i
] = GC_PSX_ID(id
[i
]);
480 static void gc_psx_process_packet(struct gc
*gc
)
482 unsigned char data
[GC_MAX_DEVICES
][GC_PSX_BYTES
];
483 unsigned char id
[GC_MAX_DEVICES
];
484 struct input_dev
*dev
;
487 gc_psx_read_packet(gc
, data
, id
);
489 for (i
= 0; i
< GC_MAX_DEVICES
; i
++) {
499 input_report_key(dev
, BTN_THUMBL
, ~data
[i
][0] & 0x04);
500 input_report_key(dev
, BTN_THUMBR
, ~data
[i
][0] & 0x02);
505 if (gc
->pads
[GC_DDR
] & gc_status_bit
[i
]) {
506 for(j
= 0; j
< 4; j
++)
507 input_report_key(dev
, gc_psx_ddr_btn
[j
], ~data
[i
][0] & (0x10 << j
));
509 for (j
= 0; j
< 4; j
++)
510 input_report_abs(dev
, gc_psx_abs
[j
+ 2], data
[i
][j
+ 2]);
512 input_report_abs(dev
, ABS_X
, 128 + !(data
[i
][0] & 0x20) * 127 - !(data
[i
][0] & 0x80) * 128);
513 input_report_abs(dev
, ABS_Y
, 128 + !(data
[i
][0] & 0x40) * 127 - !(data
[i
][0] & 0x10) * 128);
516 for (j
= 0; j
< 8; j
++)
517 input_report_key(dev
, gc_psx_btn
[j
], ~data
[i
][1] & (1 << j
));
519 input_report_key(dev
, BTN_START
, ~data
[i
][0] & 0x08);
520 input_report_key(dev
, BTN_SELECT
, ~data
[i
][0] & 0x01);
527 if (gc
->pads
[GC_DDR
] & gc_status_bit
[i
]) {
528 for(j
= 0; j
< 4; j
++)
529 input_report_key(dev
, gc_psx_ddr_btn
[j
], ~data
[i
][0] & (0x10 << j
));
531 input_report_abs(dev
, ABS_X
, 128 + !(data
[i
][0] & 0x20) * 127 - !(data
[i
][0] & 0x80) * 128);
532 input_report_abs(dev
, ABS_Y
, 128 + !(data
[i
][0] & 0x40) * 127 - !(data
[i
][0] & 0x10) * 128);
534 /* for some reason if the extra axes are left unset they drift */
535 /* for (j = 0; j < 4; j++)
536 input_report_abs(dev, gc_psx_abs[j + 2], 128);
537 * This needs to be debugged properly,
538 * maybe fuzz processing needs to be done in input_sync()
543 for (j
= 0; j
< 8; j
++)
544 input_report_key(dev
, gc_psx_btn
[j
], ~data
[i
][1] & (1 << j
));
546 input_report_key(dev
, BTN_START
, ~data
[i
][0] & 0x08);
547 input_report_key(dev
, BTN_SELECT
, ~data
[i
][0] & 0x01);
553 case 0: /* not a pad, ignore */
560 * gc_timer() initiates reads of console pads data.
563 static void gc_timer(unsigned long private)
565 struct gc
*gc
= (void *) private;
568 * N64 pads - must be read first, any read confuses them for 200 us
571 if (gc
->pads
[GC_N64
])
572 gc_n64_process_packet(gc
);
575 * NES and SNES pads or mouse
578 if (gc
->pads
[GC_NES
] || gc
->pads
[GC_SNES
] || gc
->pads
[GC_SNESMOUSE
])
579 gc_nes_process_packet(gc
);
582 * Multi and Multi2 joysticks
585 if (gc
->pads
[GC_MULTI
] || gc
->pads
[GC_MULTI2
])
586 gc_multi_process_packet(gc
);
592 if (gc
->pads
[GC_PSX
] || gc
->pads
[GC_DDR
])
593 gc_psx_process_packet(gc
);
595 mod_timer(&gc
->timer
, jiffies
+ GC_REFRESH_TIME
);
598 static int gc_open(struct input_dev
*dev
)
600 struct gc
*gc
= dev
->private;
603 err
= mutex_lock_interruptible(&gc
->mutex
);
608 parport_claim(gc
->pd
);
609 parport_write_control(gc
->pd
->port
, 0x04);
610 mod_timer(&gc
->timer
, jiffies
+ GC_REFRESH_TIME
);
613 mutex_unlock(&gc
->mutex
);
617 static void gc_close(struct input_dev
*dev
)
619 struct gc
*gc
= dev
->private;
621 mutex_lock(&gc
->mutex
);
623 del_timer_sync(&gc
->timer
);
624 parport_write_control(gc
->pd
->port
, 0x00);
625 parport_release(gc
->pd
);
627 mutex_unlock(&gc
->mutex
);
630 static int __init
gc_setup_pad(struct gc
*gc
, int idx
, int pad_type
)
632 struct input_dev
*input_dev
;
638 if (pad_type
< 1 || pad_type
> GC_MAX
) {
639 printk(KERN_WARNING
"gamecon.c: Pad type %d unknown\n", pad_type
);
643 gc
->dev
[idx
] = input_dev
= input_allocate_device();
645 printk(KERN_ERR
"gamecon.c: Not enough memory for input device\n");
649 input_dev
->name
= gc_names
[pad_type
];
650 input_dev
->phys
= gc
->phys
[idx
];
651 input_dev
->id
.bustype
= BUS_PARPORT
;
652 input_dev
->id
.vendor
= 0x0001;
653 input_dev
->id
.product
= pad_type
;
654 input_dev
->id
.version
= 0x0100;
655 input_dev
->private = gc
;
657 input_dev
->open
= gc_open
;
658 input_dev
->close
= gc_close
;
660 if (pad_type
!= GC_SNESMOUSE
) {
661 input_dev
->evbit
[0] = BIT(EV_KEY
) | BIT(EV_ABS
);
663 for (i
= 0; i
< 2; i
++)
664 input_set_abs_params(input_dev
, ABS_X
+ i
, -1, 1, 0, 0);
666 input_dev
->evbit
[0] = BIT(EV_KEY
) | BIT(EV_REL
);
668 gc
->pads
[0] |= gc_status_bit
[idx
];
669 gc
->pads
[pad_type
] |= gc_status_bit
[idx
];
674 for (i
= 0; i
< 10; i
++)
675 set_bit(gc_n64_btn
[i
], input_dev
->keybit
);
677 for (i
= 0; i
< 2; i
++) {
678 input_set_abs_params(input_dev
, ABS_X
+ i
, -127, 126, 0, 2);
679 input_set_abs_params(input_dev
, ABS_HAT0X
+ i
, -1, 1, 0, 0);
685 set_bit(BTN_LEFT
, input_dev
->keybit
);
686 set_bit(BTN_RIGHT
, input_dev
->keybit
);
687 set_bit(REL_X
, input_dev
->relbit
);
688 set_bit(REL_Y
, input_dev
->relbit
);
692 for (i
= 4; i
< 8; i
++)
693 set_bit(gc_snes_btn
[i
], input_dev
->keybit
);
695 for (i
= 0; i
< 4; i
++)
696 set_bit(gc_snes_btn
[i
], input_dev
->keybit
);
700 set_bit(BTN_THUMB
, input_dev
->keybit
);
702 set_bit(BTN_TRIGGER
, input_dev
->keybit
);
706 for (i
= 0; i
< 6; i
++)
707 input_set_abs_params(input_dev
, gc_psx_abs
[i
], 4, 252, 0, 2);
708 for (i
= 0; i
< 12; i
++)
709 set_bit(gc_psx_btn
[i
], input_dev
->keybit
);
714 for (i
= 0; i
< 4; i
++)
715 set_bit(gc_psx_ddr_btn
[i
], input_dev
->keybit
);
716 for (i
= 0; i
< 12; i
++)
717 set_bit(gc_psx_btn
[i
], input_dev
->keybit
);
725 static struct gc __init
*gc_probe(int parport
, int *pads
, int n_pads
)
729 struct pardevice
*pd
;
733 pp
= parport_find_number(parport
);
735 printk(KERN_ERR
"gamecon.c: no such parport\n");
740 pd
= parport_register_device(pp
, "gamecon", NULL
, NULL
, NULL
, PARPORT_DEV_EXCL
, NULL
);
742 printk(KERN_ERR
"gamecon.c: parport busy already - lp.o loaded?\n");
747 gc
= kzalloc(sizeof(struct gc
), GFP_KERNEL
);
749 printk(KERN_ERR
"gamecon.c: Not enough memory\n");
751 goto err_unreg_pardev
;
754 mutex_init(&gc
->mutex
);
756 init_timer(&gc
->timer
);
757 gc
->timer
.data
= (long) gc
;
758 gc
->timer
.function
= gc_timer
;
760 for (i
= 0; i
< n_pads
&& i
< GC_MAX_DEVICES
; i
++) {
764 snprintf(gc
->phys
[i
], sizeof(gc
->phys
[i
]),
765 "%s/input%d", gc
->pd
->port
->name
, i
);
766 err
= gc_setup_pad(gc
, i
, pads
[i
]);
770 err
= input_register_device(gc
->dev
[i
]);
776 printk(KERN_ERR
"gamecon.c: No valid devices specified\n");
781 parport_put_port(pp
);
785 input_free_device(gc
->dev
[i
]);
789 input_unregister_device(gc
->dev
[i
]);
793 parport_unregister_device(pd
);
795 parport_put_port(pp
);
800 static void gc_remove(struct gc
*gc
)
804 for (i
= 0; i
< GC_MAX_DEVICES
; i
++)
806 input_unregister_device(gc
->dev
[i
]);
807 parport_unregister_device(gc
->pd
);
811 static int __init
gc_init(void)
817 for (i
= 0; i
< GC_MAX_PORTS
; i
++) {
818 if (gc
[i
].nargs
== 0 || gc
[i
].args
[0] < 0)
821 if (gc
[i
].nargs
< 2) {
822 printk(KERN_ERR
"gamecon.c: at least one device must be specified\n");
827 gc_base
[i
] = gc_probe(gc
[i
].args
[0], gc
[i
].args
+ 1, gc
[i
].nargs
- 1);
828 if (IS_ERR(gc_base
[i
])) {
829 err
= PTR_ERR(gc_base
[i
]);
839 gc_remove(gc_base
[i
]);
843 return have_dev
? 0 : -ENODEV
;
846 static void __exit
gc_exit(void)
850 for (i
= 0; i
< GC_MAX_PORTS
; i
++)
852 gc_remove(gc_base
[i
]);
855 module_init(gc_init
);
856 module_exit(gc_exit
);