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