1 /* 2 * NES, SNES, N64, MultiSystem, PSX gamepad driver for Linux 3 * 4 * Copyright (c) 1999-2004 Vojtech Pavlik <vojtech@suse.cz> 5 * Copyright (c) 2004 Peter Nelson <rufus-kernel@hackish.org> 6 * 7 * Based on the work of: 8 * Andree Borrmann John Dahlstrom 9 * David Kuder Nathan Hand 10 */ 11 12 /* 13 * This program is free software; you can redistribute it and/or modify 14 * it under the terms of the GNU General Public License as published by 15 * the Free Software Foundation; either version 2 of the License, or 16 * (at your option) any later version. 17 * 18 * This program is distributed in the hope that it will be useful, 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 * GNU General Public License for more details. 22 * 23 * You should have received a copy of the GNU General Public License 24 * along with this program; if not, write to the Free Software 25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 * 27 * Should you need to contact me, the author, you can do so either by 28 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail: 29 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic 30 */ 31 32 #include <linux/kernel.h> 33 #include <linux/delay.h> 34 #include <linux/module.h> 35 #include <linux/moduleparam.h> 36 #include <linux/init.h> 37 #include <linux/parport.h> 38 #include <linux/input.h> 39 40 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); 41 MODULE_DESCRIPTION("NES, SNES, N64, MultiSystem, PSX gamepad driver"); 42 MODULE_LICENSE("GPL"); 43 44 static int gc[] __initdata = { -1, 0, 0, 0, 0, 0 }; 45 static int gc_nargs __initdata = 0; 46 module_param_array_named(map, gc, int, &gc_nargs, 0); 47 MODULE_PARM_DESC(map, "Describers first set of devices (<parport#>,<pad1>,<pad2>,..<pad5>)"); 48 49 static int gc_2[] __initdata = { -1, 0, 0, 0, 0, 0 }; 50 static int gc_nargs_2 __initdata = 0; 51 module_param_array_named(map2, gc_2, int, &gc_nargs_2, 0); 52 MODULE_PARM_DESC(map2, "Describers second set of devices"); 53 54 static int gc_3[] __initdata = { -1, 0, 0, 0, 0, 0 }; 55 static int gc_nargs_3 __initdata = 0; 56 module_param_array_named(map3, gc_3, int, &gc_nargs_3, 0); 57 MODULE_PARM_DESC(map3, "Describers third set of devices"); 58 59 __obsolete_setup("gc="); 60 __obsolete_setup("gc_2="); 61 __obsolete_setup("gc_3="); 62 63 /* see also gs_psx_delay parameter in PSX support section */ 64 65 #define GC_SNES 1 66 #define GC_NES 2 67 #define GC_NES4 3 68 #define GC_MULTI 4 69 #define GC_MULTI2 5 70 #define GC_N64 6 71 #define GC_PSX 7 72 #define GC_DDR 8 73 74 #define GC_MAX 8 75 76 #define GC_REFRESH_TIME HZ/100 77 78 struct gc { 79 struct pardevice *pd; 80 struct input_dev dev[5]; 81 struct timer_list timer; 82 unsigned char pads[GC_MAX + 1]; 83 int used; 84 struct semaphore sem; 85 char phys[5][32]; 86 }; 87 88 static struct gc *gc_base[3]; 89 90 static int gc_status_bit[] = { 0x40, 0x80, 0x20, 0x10, 0x08 }; 91 92 static char *gc_names[] = { NULL, "SNES pad", "NES pad", "NES FourPort", "Multisystem joystick", 93 "Multisystem 2-button joystick", "N64 controller", "PSX controller", 94 "PSX DDR 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 bits */ 232 #define GC_PSX_BYTES 6 /* the maximum number of bytes to read off the controller */ 233 234 #define GC_PSX_MOUSE 1 /* Mouse */ 235 #define GC_PSX_NEGCON 2 /* NegCon */ 236 #define GC_PSX_NORMAL 4 /* Digital / Analog or Rumble in Digital mode */ 237 #define GC_PSX_ANALOG 5 /* Analog in Analog mode / Rumble in Green mode */ 238 #define GC_PSX_RUMBLE 7 /* Rumble in Red mode */ 239 240 #define GC_PSX_CLOCK 0x04 /* Pin 4 */ 241 #define GC_PSX_COMMAND 0x01 /* Pin 2 */ 242 #define GC_PSX_POWER 0xf8 /* Pins 5-9 */ 243 #define GC_PSX_SELECT 0x02 /* Pin 3 */ 244 245 #define GC_PSX_ID(x) ((x) >> 4) /* High nibble is device type */ 246 #define GC_PSX_LEN(x) (((x) & 0xf) << 1) /* Low nibble is length in bytes/2 */ 247 248 static int gc_psx_delay = GC_PSX_DELAY; 249 module_param_named(psx_delay, gc_psx_delay, uint, 0); 250 MODULE_PARM_DESC(psx_delay, "Delay when accessing Sony PSX controller (usecs)"); 251 252 __obsolete_setup("gc_psx_delay="); 253 254 static short gc_psx_abs[] = { ABS_X, ABS_Y, ABS_RX, ABS_RY, ABS_HAT0X, ABS_HAT0Y }; 255 static short gc_psx_btn[] = { BTN_TL, BTN_TR, BTN_TL2, BTN_TR2, BTN_A, BTN_B, BTN_X, BTN_Y, 256 BTN_START, BTN_SELECT, BTN_THUMBL, BTN_THUMBR }; 257 static short gc_psx_ddr_btn[] = { BTN_0, BTN_1, BTN_2, BTN_3 }; 258 259 /* 260 * gc_psx_command() writes 8bit command and reads 8bit data from 261 * the psx pad. 262 */ 263 264 static void gc_psx_command(struct gc *gc, int b, unsigned char data[5]) 265 { 266 int i, j, cmd, read; 267 for (i = 0; i < 5; i++) 268 data[i] = 0; 269 270 for (i = 0; i < GC_PSX_LENGTH; i++, b >>= 1) { 271 cmd = (b & 1) ? GC_PSX_COMMAND : 0; 272 parport_write_data(gc->pd->port, cmd | GC_PSX_POWER); 273 udelay(gc_psx_delay); 274 read = parport_read_status(gc->pd->port) ^ 0x80; 275 for (j = 0; j < 5; j++) 276 data[j] |= (read & gc_status_bit[j] & (gc->pads[GC_PSX] | gc->pads[GC_DDR])) ? (1 << i) : 0; 277 parport_write_data(gc->pd->port, cmd | GC_PSX_CLOCK | GC_PSX_POWER); 278 udelay(gc_psx_delay); 279 } 280 } 281 282 /* 283 * gc_psx_read_packet() reads a whole psx packet and returns 284 * device identifier code. 285 */ 286 287 static void gc_psx_read_packet(struct gc *gc, unsigned char data[5][GC_PSX_BYTES], unsigned char id[5]) 288 { 289 int i, j, max_len = 0; 290 unsigned long flags; 291 unsigned char data2[5]; 292 293 parport_write_data(gc->pd->port, GC_PSX_CLOCK | GC_PSX_SELECT | GC_PSX_POWER); /* Select pad */ 294 udelay(gc_psx_delay); 295 parport_write_data(gc->pd->port, GC_PSX_CLOCK | GC_PSX_POWER); /* Deselect, begin command */ 296 udelay(gc_psx_delay); 297 298 local_irq_save(flags); 299 300 gc_psx_command(gc, 0x01, data2); /* Access pad */ 301 gc_psx_command(gc, 0x42, id); /* Get device ids */ 302 gc_psx_command(gc, 0, data2); /* Dump status */ 303 304 for (i =0; i < 5; i++) /* Find the longest pad */ 305 if((gc_status_bit[i] & (gc->pads[GC_PSX] | gc->pads[GC_DDR])) 306 && (GC_PSX_LEN(id[i]) > max_len) 307 && (GC_PSX_LEN(id[i]) <= GC_PSX_BYTES)) 308 max_len = GC_PSX_LEN(id[i]); 309 310 for (i = 0; i < max_len; i++) { /* Read in all the data */ 311 gc_psx_command(gc, 0, data2); 312 for (j = 0; j < 5; j++) 313 data[j][i] = data2[j]; 314 } 315 316 local_irq_restore(flags); 317 318 parport_write_data(gc->pd->port, GC_PSX_CLOCK | GC_PSX_SELECT | GC_PSX_POWER); 319 320 for(i = 0; i < 5; i++) /* Set id's to the real value */ 321 id[i] = GC_PSX_ID(id[i]); 322 } 323 324 /* 325 * gc_timer() reads and analyzes console pads data. 326 */ 327 328 #define GC_MAX_LENGTH GC_N64_LENGTH 329 330 static void gc_timer(unsigned long private) 331 { 332 struct gc *gc = (void *) private; 333 struct input_dev *dev = gc->dev; 334 unsigned char data[GC_MAX_LENGTH]; 335 unsigned char data_psx[5][GC_PSX_BYTES]; 336 int i, j, s; 337 338 /* 339 * N64 pads - must be read first, any read confuses them for 200 us 340 */ 341 342 if (gc->pads[GC_N64]) { 343 344 gc_n64_read_packet(gc, data); 345 346 for (i = 0; i < 5; i++) { 347 348 s = gc_status_bit[i]; 349 350 if (s & gc->pads[GC_N64] & ~(data[8] | data[9])) { 351 352 signed char axes[2]; 353 axes[0] = axes[1] = 0; 354 355 for (j = 0; j < 8; j++) { 356 if (data[23 - j] & s) axes[0] |= 1 << j; 357 if (data[31 - j] & s) axes[1] |= 1 << j; 358 } 359 360 input_report_abs(dev + i, ABS_X, axes[0]); 361 input_report_abs(dev + i, ABS_Y, -axes[1]); 362 363 input_report_abs(dev + i, ABS_HAT0X, !(s & data[6]) - !(s & data[7])); 364 input_report_abs(dev + i, ABS_HAT0Y, !(s & data[4]) - !(s & data[5])); 365 366 for (j = 0; j < 10; j++) 367 input_report_key(dev + i, gc_n64_btn[j], s & data[gc_n64_bytes[j]]); 368 369 input_sync(dev + i); 370 } 371 } 372 } 373 374 /* 375 * NES and SNES pads 376 */ 377 378 if (gc->pads[GC_NES] || gc->pads[GC_SNES]) { 379 380 gc_nes_read_packet(gc, gc->pads[GC_SNES] ? GC_SNES_LENGTH : GC_NES_LENGTH, data); 381 382 for (i = 0; i < 5; i++) { 383 384 s = gc_status_bit[i]; 385 386 if (s & (gc->pads[GC_NES] | gc->pads[GC_SNES])) { 387 input_report_abs(dev + i, ABS_X, !(s & data[6]) - !(s & data[7])); 388 input_report_abs(dev + i, ABS_Y, !(s & data[4]) - !(s & data[5])); 389 } 390 391 if (s & gc->pads[GC_NES]) 392 for (j = 0; j < 4; j++) 393 input_report_key(dev + i, gc_snes_btn[j], s & data[gc_nes_bytes[j]]); 394 395 if (s & gc->pads[GC_SNES]) 396 for (j = 0; j < 8; j++) 397 input_report_key(dev + i, gc_snes_btn[j], s & data[gc_snes_bytes[j]]); 398 399 input_sync(dev + i); 400 } 401 } 402 403 /* 404 * Multi and Multi2 joysticks 405 */ 406 407 if (gc->pads[GC_MULTI] || gc->pads[GC_MULTI2]) { 408 409 gc_multi_read_packet(gc, gc->pads[GC_MULTI2] ? GC_MULTI2_LENGTH : GC_MULTI_LENGTH, data); 410 411 for (i = 0; i < 5; i++) { 412 413 s = gc_status_bit[i]; 414 415 if (s & (gc->pads[GC_MULTI] | gc->pads[GC_MULTI2])) { 416 input_report_abs(dev + i, ABS_X, !(s & data[2]) - !(s & data[3])); 417 input_report_abs(dev + i, ABS_Y, !(s & data[0]) - !(s & data[1])); 418 input_report_key(dev + i, BTN_TRIGGER, s & data[4]); 419 } 420 421 if (s & gc->pads[GC_MULTI2]) 422 input_report_key(dev + i, BTN_THUMB, s & data[5]); 423 424 input_sync(dev + i); 425 } 426 } 427 428 /* 429 * PSX controllers 430 */ 431 432 if (gc->pads[GC_PSX] || gc->pads[GC_DDR]) { 433 434 gc_psx_read_packet(gc, data_psx, data); 435 436 for (i = 0; i < 5; i++) { 437 switch (data[i]) { 438 439 case GC_PSX_RUMBLE: 440 441 input_report_key(dev + i, BTN_THUMBL, ~data_psx[i][0] & 0x04); 442 input_report_key(dev + i, BTN_THUMBR, ~data_psx[i][0] & 0x02); 443 444 case GC_PSX_NEGCON: 445 case GC_PSX_ANALOG: 446 447 if(gc->pads[GC_DDR] & gc_status_bit[i]) { 448 for(j = 0; j < 4; j++) 449 input_report_key(dev + i, gc_psx_ddr_btn[j], ~data_psx[i][0] & (0x10 << j)); 450 } else { 451 for (j = 0; j < 4; j++) 452 input_report_abs(dev + i, gc_psx_abs[j+2], data_psx[i][j + 2]); 453 454 input_report_abs(dev + i, ABS_X, 128 + !(data_psx[i][0] & 0x20) * 127 - !(data_psx[i][0] & 0x80) * 128); 455 input_report_abs(dev + i, ABS_Y, 128 + !(data_psx[i][0] & 0x40) * 127 - !(data_psx[i][0] & 0x10) * 128); 456 } 457 458 for (j = 0; j < 8; j++) 459 input_report_key(dev + i, gc_psx_btn[j], ~data_psx[i][1] & (1 << j)); 460 461 input_report_key(dev + i, BTN_START, ~data_psx[i][0] & 0x08); 462 input_report_key(dev + i, BTN_SELECT, ~data_psx[i][0] & 0x01); 463 464 input_sync(dev + i); 465 466 break; 467 468 case GC_PSX_NORMAL: 469 if(gc->pads[GC_DDR] & gc_status_bit[i]) { 470 for(j = 0; j < 4; j++) 471 input_report_key(dev + i, gc_psx_ddr_btn[j], ~data_psx[i][0] & (0x10 << j)); 472 } else { 473 input_report_abs(dev + i, ABS_X, 128 + !(data_psx[i][0] & 0x20) * 127 - !(data_psx[i][0] & 0x80) * 128); 474 input_report_abs(dev + i, ABS_Y, 128 + !(data_psx[i][0] & 0x40) * 127 - !(data_psx[i][0] & 0x10) * 128); 475 476 /* for some reason if the extra axes are left unset they drift */ 477 /* for (j = 0; j < 4; j++) 478 input_report_abs(dev + i, gc_psx_abs[j+2], 128); 479 * This needs to be debugged properly, 480 * maybe fuzz processing needs to be done in input_sync() 481 * --vojtech 482 */ 483 } 484 485 for (j = 0; j < 8; j++) 486 input_report_key(dev + i, gc_psx_btn[j], ~data_psx[i][1] & (1 << j)); 487 488 input_report_key(dev + i, BTN_START, ~data_psx[i][0] & 0x08); 489 input_report_key(dev + i, BTN_SELECT, ~data_psx[i][0] & 0x01); 490 491 input_sync(dev + i); 492 493 break; 494 495 case 0: /* not a pad, ignore */ 496 break; 497 } 498 } 499 } 500 501 mod_timer(&gc->timer, jiffies + GC_REFRESH_TIME); 502 } 503 504 static int gc_open(struct input_dev *dev) 505 { 506 struct gc *gc = dev->private; 507 int err; 508 509 err = down_interruptible(&gc->sem); 510 if (err) 511 return err; 512 513 if (!gc->used++) { 514 parport_claim(gc->pd); 515 parport_write_control(gc->pd->port, 0x04); 516 mod_timer(&gc->timer, jiffies + GC_REFRESH_TIME); 517 } 518 519 up(&gc->sem); 520 return 0; 521 } 522 523 static void gc_close(struct input_dev *dev) 524 { 525 struct gc *gc = dev->private; 526 527 down(&gc->sem); 528 if (!--gc->used) { 529 del_timer_sync(&gc->timer); 530 parport_write_control(gc->pd->port, 0x00); 531 parport_release(gc->pd); 532 } 533 up(&gc->sem); 534 } 535 536 static struct gc __init *gc_probe(int *config, int nargs) 537 { 538 struct gc *gc; 539 struct parport *pp; 540 int i, j; 541 542 if (config[0] < 0) 543 return NULL; 544 545 if (nargs < 2) { 546 printk(KERN_ERR "gamecon.c: at least one device must be specified\n"); 547 return NULL; 548 } 549 550 pp = parport_find_number(config[0]); 551 552 if (!pp) { 553 printk(KERN_ERR "gamecon.c: no such parport\n"); 554 return NULL; 555 } 556 557 if (!(gc = kzalloc(sizeof(struct gc), GFP_KERNEL))) { 558 parport_put_port(pp); 559 return NULL; 560 } 561 562 init_MUTEX(&gc->sem); 563 564 gc->pd = parport_register_device(pp, "gamecon", NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL); 565 566 parport_put_port(pp); 567 568 if (!gc->pd) { 569 printk(KERN_ERR "gamecon.c: parport busy already - lp.o loaded?\n"); 570 kfree(gc); 571 return NULL; 572 } 573 574 parport_claim(gc->pd); 575 576 init_timer(&gc->timer); 577 gc->timer.data = (long) gc; 578 gc->timer.function = gc_timer; 579 580 for (i = 0; i < nargs - 1; i++) { 581 582 if (!config[i + 1]) 583 continue; 584 585 if (config[i + 1] < 1 || config[i + 1] > GC_MAX) { 586 printk(KERN_WARNING "gamecon.c: Pad type %d unknown\n", config[i + 1]); 587 continue; 588 } 589 590 gc->dev[i].private = gc; 591 gc->dev[i].open = gc_open; 592 gc->dev[i].close = gc_close; 593 594 gc->dev[i].evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 595 596 for (j = 0; j < 2; j++) { 597 set_bit(ABS_X + j, gc->dev[i].absbit); 598 gc->dev[i].absmin[ABS_X + j] = -1; 599 gc->dev[i].absmax[ABS_X + j] = 1; 600 } 601 602 gc->pads[0] |= gc_status_bit[i]; 603 gc->pads[config[i + 1]] |= gc_status_bit[i]; 604 605 switch(config[i + 1]) { 606 607 case GC_N64: 608 for (j = 0; j < 10; j++) 609 set_bit(gc_n64_btn[j], gc->dev[i].keybit); 610 611 for (j = 0; j < 2; j++) { 612 set_bit(ABS_X + j, gc->dev[i].absbit); 613 gc->dev[i].absmin[ABS_X + j] = -127; 614 gc->dev[i].absmax[ABS_X + j] = 126; 615 gc->dev[i].absflat[ABS_X + j] = 2; 616 set_bit(ABS_HAT0X + j, gc->dev[i].absbit); 617 gc->dev[i].absmin[ABS_HAT0X + j] = -1; 618 gc->dev[i].absmax[ABS_HAT0X + j] = 1; 619 } 620 621 break; 622 623 case GC_SNES: 624 for (j = 4; j < 8; j++) 625 set_bit(gc_snes_btn[j], gc->dev[i].keybit); 626 case GC_NES: 627 for (j = 0; j < 4; j++) 628 set_bit(gc_snes_btn[j], gc->dev[i].keybit); 629 break; 630 631 case GC_MULTI2: 632 set_bit(BTN_THUMB, gc->dev[i].keybit); 633 case GC_MULTI: 634 set_bit(BTN_TRIGGER, gc->dev[i].keybit); 635 break; 636 637 case GC_PSX: 638 case GC_DDR: 639 if(config[i + 1] == GC_DDR) { 640 for (j = 0; j < 4; j++) 641 set_bit(gc_psx_ddr_btn[j], gc->dev[i].keybit); 642 } else { 643 for (j = 0; j < 6; j++) { 644 set_bit(gc_psx_abs[j], gc->dev[i].absbit); 645 gc->dev[i].absmin[gc_psx_abs[j]] = 4; 646 gc->dev[i].absmax[gc_psx_abs[j]] = 252; 647 gc->dev[i].absflat[gc_psx_abs[j]] = 2; 648 } 649 } 650 651 for (j = 0; j < 12; j++) 652 set_bit(gc_psx_btn[j], gc->dev[i].keybit); 653 654 break; 655 } 656 657 sprintf(gc->phys[i], "%s/input%d", gc->pd->port->name, i); 658 659 gc->dev[i].name = gc_names[config[i + 1]]; 660 gc->dev[i].phys = gc->phys[i]; 661 gc->dev[i].id.bustype = BUS_PARPORT; 662 gc->dev[i].id.vendor = 0x0001; 663 gc->dev[i].id.product = config[i + 1]; 664 gc->dev[i].id.version = 0x0100; 665 } 666 667 parport_release(gc->pd); 668 669 if (!gc->pads[0]) { 670 parport_unregister_device(gc->pd); 671 kfree(gc); 672 return NULL; 673 } 674 675 for (i = 0; i < 5; i++) 676 if (gc->pads[0] & gc_status_bit[i]) { 677 input_register_device(gc->dev + i); 678 printk(KERN_INFO "input: %s on %s\n", gc->dev[i].name, gc->pd->port->name); 679 } 680 681 return gc; 682 } 683 684 static int __init gc_init(void) 685 { 686 gc_base[0] = gc_probe(gc, gc_nargs); 687 gc_base[1] = gc_probe(gc_2, gc_nargs_2); 688 gc_base[2] = gc_probe(gc_3, gc_nargs_3); 689 690 if (gc_base[0] || gc_base[1] || gc_base[2]) 691 return 0; 692 693 return -ENODEV; 694 } 695 696 static void __exit gc_exit(void) 697 { 698 int i, j; 699 700 for (i = 0; i < 3; i++) 701 if (gc_base[i]) { 702 for (j = 0; j < 5; j++) 703 if (gc_base[i]->pads[0] & gc_status_bit[j]) 704 input_unregister_device(gc_base[i]->dev + j); 705 parport_unregister_device(gc_base[i]->pd); 706 } 707 } 708 709 module_init(gc_init); 710 module_exit(gc_exit); 711