patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / drivers / input / joystick / gamecon.c
1 /*
2  * $Id: gamecon.c,v 1.22 2002/07/01 15:42:25 vojtech Exp $
3  *
4  *  Copyright (c) 1999-2001 Vojtech Pavlik
5  *
6  *  Based on the work of:
7  *      Andree Borrmann         John Dahlstrom
8  *      David Kuder             Nathan Hand
9  */
10
11 /*
12  * NES, SNES, N64, MultiSystem, PSX gamepad driver for Linux
13  */
14
15 /*
16  * This program is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation; either version 2 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program; if not, write to the Free Software
28  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29  *
30  * Should you need to contact me, the author, you can do so either by
31  * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
32  * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
33  */
34
35 #include <linux/kernel.h>
36 #include <linux/delay.h>
37 #include <linux/module.h>
38 #include <linux/moduleparam.h>
39 #include <linux/init.h>
40 #include <linux/parport.h>
41 #include <linux/input.h>
42
43 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
44 MODULE_DESCRIPTION("NES, SNES, N64, MultiSystem, PSX gamepad driver");
45 MODULE_LICENSE("GPL");
46
47 static int gc[] __initdata = { -1, 0, 0, 0, 0, 0 };
48 static int gc_nargs __initdata = 0;
49 module_param_array_named(map, gc, int, gc_nargs, 0);
50 MODULE_PARM_DESC(map, "Describers first set of devices (<parport#>,<pad1>,<pad2>,..<pad5>)");
51
52 static int gc_2[] __initdata = { -1, 0, 0, 0, 0, 0 };
53 static int gc_nargs_2 __initdata = 0;
54 module_param_array_named(map2, gc_2, int, gc_nargs_2, 0);
55 MODULE_PARM_DESC(map2, "Describers second set of devices");
56
57 static int gc_3[] __initdata = { -1, 0, 0, 0, 0, 0 };
58 static int gc_nargs_3 __initdata = 0;
59 module_param_array_named(map3, gc_3, int, gc_nargs_3, 0);
60 MODULE_PARM_DESC(map3, "Describers third set of devices");
61
62 __obsolete_setup("gc=");
63 __obsolete_setup("gc_2=");
64 __obsolete_setup("gc_3=");
65
66 /* see also gs_psx_delay parameter in PSX support section */
67
68 #define GC_SNES         1
69 #define GC_NES          2
70 #define GC_NES4         3
71 #define GC_MULTI        4
72 #define GC_MULTI2       5
73 #define GC_N64          6
74 #define GC_PSX          7
75
76 #define GC_MAX          7
77
78 #define GC_REFRESH_TIME HZ/100
79
80 struct gc {
81         struct pardevice *pd;
82         struct input_dev dev[5];
83         struct timer_list timer;
84         unsigned char pads[GC_MAX + 1];
85         int used;
86         char phys[5][32];
87 };
88
89 static struct gc *gc_base[3];
90
91 static int gc_status_bit[] = { 0x40, 0x80, 0x20, 0x10, 0x08 };
92
93 static char *gc_names[] = { NULL, "SNES pad", "NES pad", "NES FourPort", "Multisystem joystick",
94                                 "Multisystem 2-button joystick", "N64 controller", "PSX controller" };
95 /*
96  * N64 support.
97  */
98
99 static unsigned char gc_n64_bytes[] = { 0, 1, 13, 15, 14, 12, 10, 11, 2, 3 };
100 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 };
101
102 #define GC_N64_LENGTH           32              /* N64 bit length, not including stop bit */
103 #define GC_N64_REQUEST_LENGTH   37              /* transmit request sequence is 9 bits long */
104 #define GC_N64_DELAY            133             /* delay between transmit request, and response ready (us) */
105 #define GC_N64_REQUEST          0x1dd1111111ULL /* the request data command (encoded for 000000011) */
106 #define GC_N64_DWS              3               /* delay between write segments (required for sound playback because of ISA DMA) */
107                                                 /* GC_N64_DWS > 24 is known to fail */
108 #define GC_N64_POWER_W          0xe2            /* power during write (transmit request) */
109 #define GC_N64_POWER_R          0xfd            /* power during read */
110 #define GC_N64_OUT              0x1d            /* output bits to the 4 pads */
111                                                 /* Reading the main axes of any N64 pad is known to fail if the corresponding bit */
112                                                 /* in GC_N64_OUT is pulled low on the output port (by any routine) for more */
113                                                 /* than 123 us */
114 #define GC_N64_CLOCK            0x02            /* clock bits for read */
115
116 /*
117  * gc_n64_read_packet() reads an N64 packet.
118  * Each pad uses one bit per byte. So all pads connected to this port are read in parallel.
119  */
120
121 static void gc_n64_read_packet(struct gc *gc, unsigned char *data)
122 {
123         int i;
124         unsigned long flags;
125
126 /*
127  * Request the pad to transmit data
128  */
129
130         local_irq_save(flags);
131         for (i = 0; i < GC_N64_REQUEST_LENGTH; i++) {
132                 parport_write_data(gc->pd->port, GC_N64_POWER_W | ((GC_N64_REQUEST >> i) & 1 ? GC_N64_OUT : 0));
133                 udelay(GC_N64_DWS);
134         }
135         local_irq_restore(flags);
136
137 /*
138  * Wait for the pad response to be loaded into the 33-bit register of the adapter
139  */
140
141         udelay(GC_N64_DELAY);
142
143 /*
144  * Grab data (ignoring the last bit, which is a stop bit)
145  */
146
147         for (i = 0; i < GC_N64_LENGTH; i++) {
148                 parport_write_data(gc->pd->port, GC_N64_POWER_R);
149                 data[i] = parport_read_status(gc->pd->port);
150                 parport_write_data(gc->pd->port, GC_N64_POWER_R | GC_N64_CLOCK);
151          }
152
153 /*
154  * We must wait 200 ms here for the controller to reinitialize before the next read request.
155  * No worries as long as gc_read is polled less frequently than this.
156  */
157
158 }
159
160 /*
161  * NES/SNES support.
162  */
163
164 #define GC_NES_DELAY    6       /* Delay between bits - 6us */
165 #define GC_NES_LENGTH   8       /* The NES pads use 8 bits of data */
166 #define GC_SNES_LENGTH  12      /* The SNES true length is 16, but the last 4 bits are unused */
167
168 #define GC_NES_POWER    0xfc
169 #define GC_NES_CLOCK    0x01
170 #define GC_NES_LATCH    0x02
171
172 static unsigned char gc_nes_bytes[] = { 0, 1, 2, 3 };
173 static unsigned char gc_snes_bytes[] = { 8, 0, 2, 3, 9, 1, 10, 11 };
174 static short gc_snes_btn[] = { BTN_A, BTN_B, BTN_SELECT, BTN_START, BTN_X, BTN_Y, BTN_TL, BTN_TR };
175
176 /*
177  * gc_nes_read_packet() reads a NES/SNES packet.
178  * Each pad uses one bit per byte. So all pads connected to
179  * this port are read in parallel.
180  */
181
182 static void gc_nes_read_packet(struct gc *gc, int length, unsigned char *data)
183 {
184         int i;
185
186         parport_write_data(gc->pd->port, GC_NES_POWER | GC_NES_CLOCK | GC_NES_LATCH);
187         udelay(GC_NES_DELAY * 2);
188         parport_write_data(gc->pd->port, GC_NES_POWER | GC_NES_CLOCK);
189
190         for (i = 0; i < length; i++) {
191                 udelay(GC_NES_DELAY);
192                 parport_write_data(gc->pd->port, GC_NES_POWER);
193                 data[i] = parport_read_status(gc->pd->port) ^ 0x7f;
194                 udelay(GC_NES_DELAY);
195                 parport_write_data(gc->pd->port, GC_NES_POWER | GC_NES_CLOCK);
196         }
197 }
198
199 /*
200  * Multisystem joystick support
201  */
202
203 #define GC_MULTI_LENGTH         5       /* Multi system joystick packet length is 5 */
204 #define GC_MULTI2_LENGTH        6       /* One more bit for one more button */
205
206 /*
207  * gc_multi_read_packet() reads a Multisystem joystick packet.
208  */
209
210 static void gc_multi_read_packet(struct gc *gc, int length, unsigned char *data)
211 {
212         int i;
213
214         for (i = 0; i < length; i++) {
215                 parport_write_data(gc->pd->port, ~(1 << i));
216                 data[i] = parport_read_status(gc->pd->port) ^ 0x7f;
217         }
218 }
219
220 /*
221  * PSX support
222  *
223  * See documentation at:
224  *      http://www.dim.com/~mackys/psxmemcard/ps-eng2.txt
225  *      http://www.gamesx.com/controldata/psxcont/psxcont.htm
226  *      ftp://milano.usal.es/pablo/
227  *
228  */
229
230 #define GC_PSX_DELAY    25              /* 25 usec */
231 #define GC_PSX_LENGTH   8               /* talk to the controller in bytes */
232
233 #define GC_PSX_MOUSE    1               /* Mouse */
234 #define GC_PSX_NEGCON   2               /* NegCon */
235 #define GC_PSX_NORMAL   4               /* Digital / Analog or Rumble in Digital mode  */
236 #define GC_PSX_ANALOG   5               /* Analog in Analog mode / Rumble in Green mode */
237 #define GC_PSX_RUMBLE   7               /* Rumble in Red mode */
238
239 #define GC_PSX_CLOCK    0x04            /* Pin 4 */
240 #define GC_PSX_COMMAND  0x01            /* Pin 1 */
241 #define GC_PSX_POWER    0xf8            /* Pins 5-9 */
242 #define GC_PSX_SELECT   0x02            /* Pin 3 */
243
244 #define GC_PSX_ID(x)    ((x) >> 4)      /* High nibble is device type */
245 #define GC_PSX_LEN(x)   ((x) & 0xf)     /* Low nibble is length in words */
246
247 static int gc_psx_delay = GC_PSX_DELAY;
248 module_param_named(psx_delay, gc_psx_delay, uint, 0);
249 MODULE_PARM_DESC(psx_delay, "Delay when accessing Sony PSX controller (usecs)");
250
251 __obsolete_setup("gc_psx_delay=");
252
253 static short gc_psx_abs[] = { ABS_X, ABS_Y, ABS_RX, ABS_RY, ABS_HAT0X, ABS_HAT0Y };
254 static short gc_psx_btn[] = { BTN_TL, BTN_TR, BTN_TL2, BTN_TR2, BTN_A, BTN_B, BTN_X, BTN_Y,
255                                 BTN_START, BTN_SELECT, BTN_THUMBL, BTN_THUMBR };
256
257 /*
258  * gc_psx_command() writes 8bit command and reads 8bit data from
259  * the psx pad.
260  */
261
262 static int gc_psx_command(struct gc *gc, int b)
263 {
264         int i, cmd, data = 0;
265
266         for (i = 0; i < 8; i++, b >>= 1) {
267                 cmd = (b & 1) ? GC_PSX_COMMAND : 0;
268                 parport_write_data(gc->pd->port, cmd | GC_PSX_POWER);
269                 udelay(gc_psx_delay);
270                 data |= ((parport_read_status(gc->pd->port) ^ 0x80) & gc->pads[GC_PSX]) ? (1 << i) : 0;
271                 parport_write_data(gc->pd->port, cmd | GC_PSX_CLOCK | GC_PSX_POWER);
272                 udelay(gc_psx_delay);
273         }
274         return data;
275 }
276
277 /*
278  * gc_psx_read_packet() reads a whole psx packet and returns
279  * device identifier code.
280  */
281
282 static int gc_psx_read_packet(struct gc *gc, unsigned char *data)
283 {
284         int i, id;
285         unsigned long flags;
286
287         parport_write_data(gc->pd->port, GC_PSX_CLOCK | GC_PSX_SELECT | GC_PSX_POWER);  /* Select pad */
288         udelay(gc_psx_delay * 2);
289         parport_write_data(gc->pd->port, GC_PSX_CLOCK | GC_PSX_POWER);                  /* Deselect, begin command */
290         udelay(gc_psx_delay * 2);
291
292         local_irq_save(flags);
293
294         gc_psx_command(gc, 0x01);                                                       /* Access pad */
295         id = gc_psx_command(gc, 0x42);                                                  /* Get device id */
296         if (gc_psx_command(gc, 0) == 0x5a) {                                            /* Okay? */
297                 for (i = 0; i < GC_PSX_LEN(id) * 2; i++)
298                         data[i] = gc_psx_command(gc, 0);
299         } else id = 0;
300
301         local_irq_restore(flags);
302
303         parport_write_data(gc->pd->port, GC_PSX_CLOCK | GC_PSX_SELECT | GC_PSX_POWER);
304
305         return GC_PSX_ID(id);
306 }
307
308 /*
309  * gc_timer() reads and analyzes console pads data.
310  */
311
312 #define GC_MAX_LENGTH GC_N64_LENGTH
313
314 static void gc_timer(unsigned long private)
315 {
316         struct gc *gc = (void *) private;
317         struct input_dev *dev = gc->dev;
318         unsigned char data[GC_MAX_LENGTH];
319         int i, j, s;
320
321 /*
322  * N64 pads - must be read first, any read confuses them for 200 us
323  */
324
325         if (gc->pads[GC_N64]) {
326
327                 gc_n64_read_packet(gc, data);
328
329                 for (i = 0; i < 5; i++) {
330
331                         s = gc_status_bit[i];
332
333                         if (s & gc->pads[GC_N64] & ~(data[8] | data[9])) {
334
335                                 signed char axes[2];
336                                 axes[0] = axes[1] = 0;
337
338                                 for (j = 0; j < 8; j++) {
339                                         if (data[23 - j] & s) axes[0] |= 1 << j;
340                                         if (data[31 - j] & s) axes[1] |= 1 << j;
341                                 }
342
343                                 input_report_abs(dev + i, ABS_X,  axes[0]);
344                                 input_report_abs(dev + i, ABS_Y, -axes[1]);
345
346                                 input_report_abs(dev + i, ABS_HAT0X, !(s & data[6]) - !(s & data[7]));
347                                 input_report_abs(dev + i, ABS_HAT0Y, !(s & data[4]) - !(s & data[5]));
348
349                                 for (j = 0; j < 10; j++)
350                                         input_report_key(dev + i, gc_n64_btn[j], s & data[gc_n64_bytes[j]]);
351
352                                 input_sync(dev + i);
353                         }
354                 }
355         }
356
357 /*
358  * NES and SNES pads
359  */
360
361         if (gc->pads[GC_NES] || gc->pads[GC_SNES]) {
362
363                 gc_nes_read_packet(gc, gc->pads[GC_SNES] ? GC_SNES_LENGTH : GC_NES_LENGTH, data);
364
365                 for (i = 0; i < 5; i++) {
366
367                         s = gc_status_bit[i];
368
369                         if (s & (gc->pads[GC_NES] | gc->pads[GC_SNES])) {
370                                 input_report_abs(dev + i, ABS_X, !(s & data[6]) - !(s & data[7]));
371                                 input_report_abs(dev + i, ABS_Y, !(s & data[4]) - !(s & data[5]));
372                         }
373
374                         if (s & gc->pads[GC_NES])
375                                 for (j = 0; j < 4; j++)
376                                         input_report_key(dev + i, gc_snes_btn[j], s & data[gc_nes_bytes[j]]);
377
378                         if (s & gc->pads[GC_SNES])
379                                 for (j = 0; j < 8; j++)
380                                         input_report_key(dev + i, gc_snes_btn[j], s & data[gc_snes_bytes[j]]);
381
382                         input_sync(dev + i);
383                 }
384         }
385
386 /*
387  * Multi and Multi2 joysticks
388  */
389
390         if (gc->pads[GC_MULTI] || gc->pads[GC_MULTI2]) {
391
392                 gc_multi_read_packet(gc, gc->pads[GC_MULTI2] ? GC_MULTI2_LENGTH : GC_MULTI_LENGTH, data);
393
394                 for (i = 0; i < 5; i++) {
395
396                         s = gc_status_bit[i];
397
398                         if (s & (gc->pads[GC_MULTI] | gc->pads[GC_MULTI2])) {
399                                 input_report_abs(dev + i, ABS_X,  !(s & data[2]) - !(s & data[3]));
400                                 input_report_abs(dev + i, ABS_Y,  !(s & data[0]) - !(s & data[1]));
401                                 input_report_key(dev + i, BTN_TRIGGER, s & data[4]);
402                         }
403
404                         if (s & gc->pads[GC_MULTI2])
405                                 input_report_key(dev + i, BTN_THUMB, s & data[5]);
406
407                         input_sync(dev + i);
408                 }
409         }
410
411 /*
412  * PSX controllers
413  */
414
415         if (gc->pads[GC_PSX]) {
416
417                 for (i = 0; i < 5; i++)
418                         if (gc->pads[GC_PSX] & gc_status_bit[i])
419                                 break;
420
421                 switch (gc_psx_read_packet(gc, data)) {
422
423                         case GC_PSX_RUMBLE:
424
425                                 input_report_key(dev + i, BTN_THUMBL, ~data[0] & 0x04);
426                                 input_report_key(dev + i, BTN_THUMBR, ~data[0] & 0x02);
427                                 input_sync(dev + i);
428
429                         case GC_PSX_NEGCON:
430                         case GC_PSX_ANALOG:
431
432                                 for (j = 0; j < 4; j++)
433                                         input_report_abs(dev + i, gc_psx_abs[j], data[j + 2]);
434
435                                 input_report_abs(dev + i, ABS_HAT0X, !(data[0] & 0x20) - !(data[0] & 0x80));
436                                 input_report_abs(dev + i, ABS_HAT0Y, !(data[0] & 0x40) - !(data[0] & 0x10));
437
438                                 for (j = 0; j < 8; j++)
439                                         input_report_key(dev + i, gc_psx_btn[j], ~data[1] & (1 << j));
440
441                                 input_report_key(dev + i, BTN_START,  ~data[0] & 0x08);
442                                 input_report_key(dev + i, BTN_SELECT, ~data[0] & 0x01);
443
444                                 input_sync(dev + i);
445
446                                 break;
447
448                         case GC_PSX_NORMAL:
449
450                                 input_report_abs(dev + i, ABS_X, 128 + !(data[0] & 0x20) * 127 - !(data[0] & 0x80) * 128);
451                                 input_report_abs(dev + i, ABS_Y, 128 + !(data[0] & 0x40) * 127 - !(data[0] & 0x10) * 128);
452
453                                 for (j = 0; j < 8; j++)
454                                         input_report_key(dev + i, gc_psx_btn[j], ~data[1] & (1 << j));
455
456                                 input_report_key(dev + i, BTN_START,  ~data[0] & 0x08);
457                                 input_report_key(dev + i, BTN_SELECT, ~data[0] & 0x01);
458
459                                 input_sync(dev + i);
460
461                                 break;
462                 }
463         }
464
465         mod_timer(&gc->timer, jiffies + GC_REFRESH_TIME);
466 }
467
468 static int gc_open(struct input_dev *dev)
469 {
470         struct gc *gc = dev->private;
471         if (!gc->used++) {
472                 parport_claim(gc->pd);
473                 parport_write_control(gc->pd->port, 0x04);
474                 mod_timer(&gc->timer, jiffies + GC_REFRESH_TIME);
475         }
476         return 0;
477 }
478
479 static void gc_close(struct input_dev *dev)
480 {
481         struct gc *gc = dev->private;
482         if (!--gc->used) {
483                 del_timer(&gc->timer);
484                 parport_write_control(gc->pd->port, 0x00);
485                 parport_release(gc->pd);
486         }
487 }
488
489 static struct gc __init *gc_probe(int *config, int nargs)
490 {
491         struct gc *gc;
492         struct parport *pp;
493         int i, j, psx;
494         unsigned char data[32];
495
496         if (config[0] < 0)
497                 return NULL;
498
499         if (nargs < 2) {
500                 printk(KERN_ERR "gamecon.c: at least one device must be specified\n");
501                 return NULL;
502         }
503
504         pp = parport_find_number(config[0]);
505
506         if (!pp) {
507                 printk(KERN_ERR "gamecon.c: no such parport\n");
508                 return NULL;
509         }
510
511         if (!(gc = kmalloc(sizeof(struct gc), GFP_KERNEL))) {
512                 parport_put_port(pp);
513                 return NULL;
514         }
515         memset(gc, 0, sizeof(struct gc));
516
517         gc->pd = parport_register_device(pp, "gamecon", NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL);
518
519         parport_put_port(pp);
520
521         if (!gc->pd) {
522                 printk(KERN_ERR "gamecon.c: parport busy already - lp.o loaded?\n");
523                 kfree(gc);
524                 return NULL;
525         }
526
527         parport_claim(gc->pd);
528
529         init_timer(&gc->timer);
530         gc->timer.data = (long) gc;
531         gc->timer.function = gc_timer;
532
533         for (i = 0; i < nargs - 1; i++) {
534
535                 if (!config[i + 1])
536                         continue;
537
538                 if (config[i + 1] < 1 || config[i + 1] > GC_MAX) {
539                         printk(KERN_WARNING "gamecon.c: Pad type %d unknown\n", config[i + 1]);
540                         continue;
541                 }
542
543                 gc->dev[i].private = gc;
544                 gc->dev[i].open = gc_open;
545                 gc->dev[i].close = gc_close;
546
547                 gc->dev[i].evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
548
549                 for (j = 0; j < 2; j++) {
550                         set_bit(ABS_X + j, gc->dev[i].absbit);
551                         gc->dev[i].absmin[ABS_X + j] = -1;
552                         gc->dev[i].absmax[ABS_X + j] =  1;
553                 }
554
555                 gc->pads[0] |= gc_status_bit[i];
556                 gc->pads[config[i + 1]] |= gc_status_bit[i];
557
558                 switch(config[i + 1]) {
559
560                         case GC_N64:
561                                 for (j = 0; j < 10; j++)
562                                         set_bit(gc_n64_btn[j], gc->dev[i].keybit);
563
564                                 for (j = 0; j < 2; j++) {
565                                         set_bit(ABS_X + j, gc->dev[i].absbit);
566                                         gc->dev[i].absmin[ABS_X + j] = -127;
567                                         gc->dev[i].absmax[ABS_X + j] =  126;
568                                         gc->dev[i].absflat[ABS_X + j] = 2;
569                                         set_bit(ABS_HAT0X + j, gc->dev[i].absbit);
570                                         gc->dev[i].absmin[ABS_HAT0X + j] = -1;
571                                         gc->dev[i].absmax[ABS_HAT0X + j] =  1;
572                                 }
573
574                                 break;
575
576                         case GC_SNES:
577                                 for (j = 4; j < 8; j++)
578                                         set_bit(gc_snes_btn[j], gc->dev[i].keybit);
579                         case GC_NES:
580                                 for (j = 0; j < 4; j++)
581                                         set_bit(gc_snes_btn[j], gc->dev[i].keybit);
582                                 break;
583
584                         case GC_MULTI2:
585                                 set_bit(BTN_THUMB, gc->dev[i].keybit);
586                         case GC_MULTI:
587                                 set_bit(BTN_TRIGGER, gc->dev[i].keybit);
588                                 break;
589
590                         case GC_PSX:
591
592                                 psx = gc_psx_read_packet(gc, data);
593
594                                 switch(psx) {
595                                         case GC_PSX_NEGCON:
596                                         case GC_PSX_NORMAL:
597                                         case GC_PSX_ANALOG:
598                                         case GC_PSX_RUMBLE:
599
600                                                 for (j = 0; j < 6; j++) {
601                                                         psx = gc_psx_abs[j];
602                                                         set_bit(psx, gc->dev[i].absbit);
603                                                         if (j < 4) {
604                                                                 gc->dev[i].absmin[psx] = 4;
605                                                                 gc->dev[i].absmax[psx] = 252;
606                                                                 gc->dev[i].absflat[psx] = 2;
607                                                         } else {
608                                                                 gc->dev[i].absmin[psx] = -1;
609                                                                 gc->dev[i].absmax[psx] = 1;
610                                                         }
611                                                 }
612
613                                                 for (j = 0; j < 12; j++)
614                                                         set_bit(gc_psx_btn[j], gc->dev[i].keybit);
615
616                                                 break;
617
618                                         case 0:
619                                                 gc->pads[GC_PSX] &= ~gc_status_bit[i];
620                                                 printk(KERN_ERR "gamecon.c: No PSX controller found.\n");
621                                                 break;
622
623                                         default:
624                                                 gc->pads[GC_PSX] &= ~gc_status_bit[i];
625                                                 printk(KERN_WARNING "gamecon.c: Unsupported PSX controller %#x,"
626                                                         " please report to <vojtech@ucw.cz>.\n", psx);
627                                 }
628                                 break;
629                 }
630
631                 sprintf(gc->phys[i], "%s/input%d", gc->pd->port->name, i);
632
633                 gc->dev[i].name = gc_names[config[i + 1]];
634                 gc->dev[i].phys = gc->phys[i];
635                 gc->dev[i].id.bustype = BUS_PARPORT;
636                 gc->dev[i].id.vendor = 0x0001;
637                 gc->dev[i].id.product = config[i + 1];
638                 gc->dev[i].id.version = 0x0100;
639         }
640
641         parport_release(gc->pd);
642
643         if (!gc->pads[0]) {
644                 parport_unregister_device(gc->pd);
645                 kfree(gc);
646                 return NULL;
647         }
648
649         for (i = 0; i < 5; i++)
650                 if (gc->pads[0] & gc_status_bit[i]) {
651                         input_register_device(gc->dev + i);
652                         printk(KERN_INFO "input: %s on %s\n", gc->dev[i].name, gc->pd->port->name);
653                 }
654
655         return gc;
656 }
657
658 int __init gc_init(void)
659 {
660         gc_base[0] = gc_probe(gc, gc_nargs);
661         gc_base[1] = gc_probe(gc_2, gc_nargs_2);
662         gc_base[2] = gc_probe(gc_3, gc_nargs_3);
663
664         if (gc_base[0] || gc_base[1] || gc_base[2])
665                 return 0;
666
667         return -ENODEV;
668 }
669
670 void __exit gc_exit(void)
671 {
672         int i, j;
673
674         for (i = 0; i < 3; i++)
675                 if (gc_base[i]) {
676                         for (j = 0; j < 5; j++)
677                                 if (gc_base[i]->pads[0] & gc_status_bit[j])
678                                         input_unregister_device(gc_base[i]->dev + j);
679                         parport_unregister_device(gc_base[i]->pd);
680                 }
681 }
682
683 module_init(gc_init);
684 module_exit(gc_exit);