aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2010-02-21 23:54:28 -0500
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2010-02-22 01:09:49 -0500
commitd38fcb9690532e6e2e064d711262b14d638113b9 (patch)
tree714536bba2d5872e99c8c5769b7982c1eeb5cb7f /drivers/input
parent7aa9e0e8263259f4517ba1788f4fbaa88e878400 (diff)
Input: gamecon - fix some formatting issues
Fix formatting of 'switch' statements and change the code to stay closer to 80 column limit where it does not hurt code readability. Tested-by: Scott Moreau <oreaus@gmail.com> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers/input')
-rw-r--r--drivers/input/joystick/gamecon.c347
1 files changed, 194 insertions, 153 deletions
diff --git a/drivers/input/joystick/gamecon.c b/drivers/input/joystick/gamecon.c
index bbde4e524da3..ec01bea8dc81 100644
--- a/drivers/input/joystick/gamecon.c
+++ b/drivers/input/joystick/gamecon.c
@@ -93,15 +93,21 @@ static struct gc *gc_base[3];
93 93
94static int gc_status_bit[] = { 0x40, 0x80, 0x20, 0x10, 0x08 }; 94static int gc_status_bit[] = { 0x40, 0x80, 0x20, 0x10, 0x08 };
95 95
96static char *gc_names[] = { NULL, "SNES pad", "NES pad", "NES FourPort", "Multisystem joystick", 96static char *gc_names[] = {
97 "Multisystem 2-button joystick", "N64 controller", "PSX controller", 97 NULL, "SNES pad", "NES pad", "NES FourPort", "Multisystem joystick",
98 "PSX DDR controller", "SNES mouse" }; 98 "Multisystem 2-button joystick", "N64 controller", "PSX controller",
99 "PSX DDR controller", "SNES mouse"
100};
101
99/* 102/*
100 * N64 support. 103 * N64 support.
101 */ 104 */
102 105
103static unsigned char gc_n64_bytes[] = { 0, 1, 13, 15, 14, 12, 10, 11, 2, 3 }; 106static unsigned char gc_n64_bytes[] = { 0, 1, 13, 15, 14, 12, 10, 11, 2, 3 };
104static short gc_n64_btn[] = { BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_TL, BTN_TR, BTN_TRIGGER, BTN_START }; 107static short gc_n64_btn[] = {
108 BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z,
109 BTN_TL, BTN_TR, BTN_TRIGGER, BTN_START
110};
105 111
106#define GC_N64_LENGTH 32 /* N64 bit length, not including stop bit */ 112#define GC_N64_LENGTH 32 /* N64 bit length, not including stop bit */
107#define GC_N64_STOP_LENGTH 5 /* Length of encoded stop bit */ 113#define GC_N64_STOP_LENGTH 5 /* Length of encoded stop bit */
@@ -157,7 +163,8 @@ static void gc_n64_send_stop_bit(struct gc *gc, unsigned char target)
157 163
158/* 164/*
159 * gc_n64_read_packet() reads an N64 packet. 165 * gc_n64_read_packet() reads an N64 packet.
160 * Each pad uses one bit per byte. So all pads connected to this port are read in parallel. 166 * Each pad uses one bit per byte. So all pads connected to this port
167 * are read in parallel.
161 */ 168 */
162 169
163static void gc_n64_read_packet(struct gc *gc, unsigned char *data) 170static void gc_n64_read_packet(struct gc *gc, unsigned char *data)
@@ -175,7 +182,8 @@ static void gc_n64_read_packet(struct gc *gc, unsigned char *data)
175 local_irq_restore(flags); 182 local_irq_restore(flags);
176 183
177/* 184/*
178 * Wait for the pad response to be loaded into the 33-bit register of the adapter 185 * Wait for the pad response to be loaded into the 33-bit register
186 * of the adapter.
179 */ 187 */
180 188
181 udelay(GC_N64_DELAY); 189 udelay(GC_N64_DELAY);
@@ -192,8 +200,9 @@ static void gc_n64_read_packet(struct gc *gc, unsigned char *data)
192 } 200 }
193 201
194/* 202/*
195 * We must wait 200 ms here for the controller to reinitialize before the next read request. 203 * We must wait 200 ms here for the controller to reinitialize before
196 * No worries as long as gc_read is polled less frequently than this. 204 * the next read request. No worries as long as gc_read is polled less
205 * frequently than this.
197 */ 206 */
198 207
199} 208}
@@ -201,9 +210,9 @@ static void gc_n64_read_packet(struct gc *gc, unsigned char *data)
201static void gc_n64_process_packet(struct gc *gc) 210static void gc_n64_process_packet(struct gc *gc)
202{ 211{
203 unsigned char data[GC_N64_LENGTH]; 212 unsigned char data[GC_N64_LENGTH];
204 signed char axes[2];
205 struct input_dev *dev; 213 struct input_dev *dev;
206 int i, j, s; 214 int i, j, s;
215 signed char x, y;
207 216
208 gc_n64_read_packet(gc, data); 217 gc_n64_read_packet(gc, data);
209 218
@@ -217,23 +226,26 @@ static void gc_n64_process_packet(struct gc *gc)
217 226
218 if (s & gc->pads[GC_N64] & ~(data[8] | data[9])) { 227 if (s & gc->pads[GC_N64] & ~(data[8] | data[9])) {
219 228
220 axes[0] = axes[1] = 0; 229 x = y = 0;
221 230
222 for (j = 0; j < 8; j++) { 231 for (j = 0; j < 8; j++) {
223 if (data[23 - j] & s) 232 if (data[23 - j] & s)
224 axes[0] |= 1 << j; 233 x |= 1 << j;
225 if (data[31 - j] & s) 234 if (data[31 - j] & s)
226 axes[1] |= 1 << j; 235 y |= 1 << j;
227 } 236 }
228 237
229 input_report_abs(dev, ABS_X, axes[0]); 238 input_report_abs(dev, ABS_X, x);
230 input_report_abs(dev, ABS_Y, -axes[1]); 239 input_report_abs(dev, ABS_Y, -y);
231 240
232 input_report_abs(dev, ABS_HAT0X, !(s & data[6]) - !(s & data[7])); 241 input_report_abs(dev, ABS_HAT0X,
233 input_report_abs(dev, ABS_HAT0Y, !(s & data[4]) - !(s & data[5])); 242 !(s & data[6]) - !(s & data[7]));
243 input_report_abs(dev, ABS_HAT0Y,
244 !(s & data[4]) - !(s & data[5]));
234 245
235 for (j = 0; j < 10; j++) 246 for (j = 0; j < 10; j++)
236 input_report_key(dev, gc_n64_btn[j], s & data[gc_n64_bytes[j]]); 247 input_report_key(dev, gc_n64_btn[j],
248 s & data[gc_n64_bytes[j]]);
237 249
238 input_sync(dev); 250 input_sync(dev);
239 } 251 }
@@ -321,7 +333,9 @@ static int __init gc_n64_init_ff(struct input_dev *dev, int i)
321 333
322static unsigned char gc_nes_bytes[] = { 0, 1, 2, 3 }; 334static unsigned char gc_nes_bytes[] = { 0, 1, 2, 3 };
323static unsigned char gc_snes_bytes[] = { 8, 0, 2, 3, 9, 1, 10, 11 }; 335static unsigned char gc_snes_bytes[] = { 8, 0, 2, 3, 9, 1, 10, 11 };
324static short gc_snes_btn[] = { BTN_A, BTN_B, BTN_SELECT, BTN_START, BTN_X, BTN_Y, BTN_TL, BTN_TR }; 336static short gc_snes_btn[] = {
337 BTN_A, BTN_B, BTN_SELECT, BTN_START, BTN_X, BTN_Y, BTN_TL, BTN_TR
338};
325 339
326/* 340/*
327 * gc_nes_read_packet() reads a NES/SNES packet. 341 * gc_nes_read_packet() reads a NES/SNES packet.
@@ -373,16 +387,19 @@ static void gc_nes_process_packet(struct gc *gc)
373 387
374 if (s & gc->pads[GC_NES]) 388 if (s & gc->pads[GC_NES])
375 for (j = 0; j < 4; j++) 389 for (j = 0; j < 4; j++)
376 input_report_key(dev, gc_snes_btn[j], s & data[gc_nes_bytes[j]]); 390 input_report_key(dev, gc_snes_btn[j],
391 s & data[gc_nes_bytes[j]]);
377 392
378 if (s & gc->pads[GC_SNES]) 393 if (s & gc->pads[GC_SNES])
379 for (j = 0; j < 8; j++) 394 for (j = 0; j < 8; j++)
380 input_report_key(dev, gc_snes_btn[j], s & data[gc_snes_bytes[j]]); 395 input_report_key(dev, gc_snes_btn[j],
396 s & data[gc_snes_bytes[j]]);
381 397
382 if (s & gc->pads[GC_SNESMOUSE]) { 398 if (s & gc->pads[GC_SNESMOUSE]) {
383 /* 399 /*
384 * The 4 unused bits from SNES controllers appear to be ID bits 400 * The 4 unused bits from SNES controllers appear
385 * so use them to make sure iwe are dealing with a mouse. 401 * to be ID bits so use them to make sure we are
402 * dealing with a mouse.
386 * gamepad is connected. This is important since 403 * gamepad is connected. This is important since
387 * my SNES gamepad sends 1's for bits 16-31, which 404 * my SNES gamepad sends 1's for bits 16-31, which
388 * cause the mouse pointer to quickly move to the 405 * cause the mouse pointer to quickly move to the
@@ -445,10 +462,11 @@ static void gc_multi_read_packet(struct gc *gc, int length, unsigned char *data)
445static void gc_multi_process_packet(struct gc *gc) 462static void gc_multi_process_packet(struct gc *gc)
446{ 463{
447 unsigned char data[GC_MULTI2_LENGTH]; 464 unsigned char data[GC_MULTI2_LENGTH];
465 int data_len = gc->pads[GC_MULTI2] ? GC_MULTI2_LENGTH : GC_MULTI_LENGTH;
448 struct input_dev *dev; 466 struct input_dev *dev;
449 int i, s; 467 int i, s;
450 468
451 gc_multi_read_packet(gc, gc->pads[GC_MULTI2] ? GC_MULTI2_LENGTH : GC_MULTI_LENGTH, data); 469 gc_multi_read_packet(gc, data_len, data);
452 470
453 for (i = 0; i < GC_MAX_DEVICES; i++) { 471 for (i = 0; i < GC_MAX_DEVICES; i++) {
454 472
@@ -459,8 +477,10 @@ static void gc_multi_process_packet(struct gc *gc)
459 s = gc_status_bit[i]; 477 s = gc_status_bit[i];
460 478
461 if (s & (gc->pads[GC_MULTI] | gc->pads[GC_MULTI2])) { 479 if (s & (gc->pads[GC_MULTI] | gc->pads[GC_MULTI2])) {
462 input_report_abs(dev, ABS_X, !(s & data[2]) - !(s & data[3])); 480 input_report_abs(dev, ABS_X,
463 input_report_abs(dev, ABS_Y, !(s & data[0]) - !(s & data[1])); 481 !(s & data[2]) - !(s & data[3]));
482 input_report_abs(dev, ABS_Y,
483 !(s & data[0]) - !(s & data[1]));
464 input_report_key(dev, BTN_TRIGGER, s & data[4]); 484 input_report_key(dev, BTN_TRIGGER, s & data[4]);
465 } 485 }
466 486
@@ -503,9 +523,13 @@ static int gc_psx_delay = GC_PSX_DELAY;
503module_param_named(psx_delay, gc_psx_delay, uint, 0); 523module_param_named(psx_delay, gc_psx_delay, uint, 0);
504MODULE_PARM_DESC(psx_delay, "Delay when accessing Sony PSX controller (usecs)"); 524MODULE_PARM_DESC(psx_delay, "Delay when accessing Sony PSX controller (usecs)");
505 525
506static short gc_psx_abs[] = { ABS_X, ABS_Y, ABS_RX, ABS_RY, ABS_HAT0X, ABS_HAT0Y }; 526static short gc_psx_abs[] = {
507static short gc_psx_btn[] = { BTN_TL, BTN_TR, BTN_TL2, BTN_TR2, BTN_A, BTN_B, BTN_X, BTN_Y, 527 ABS_X, ABS_Y, ABS_RX, ABS_RY, ABS_HAT0X, ABS_HAT0Y
508 BTN_START, BTN_SELECT, BTN_THUMBL, BTN_THUMBR }; 528};
529static short gc_psx_btn[] = {
530 BTN_TL, BTN_TR, BTN_TL2, BTN_TR2, BTN_A, BTN_B, BTN_X, BTN_Y,
531 BTN_START, BTN_SELECT, BTN_THUMBL, BTN_THUMBR
532};
509static short gc_psx_ddr_btn[] = { BTN_0, BTN_1, BTN_2, BTN_3 }; 533static short gc_psx_ddr_btn[] = { BTN_0, BTN_1, BTN_2, BTN_3 };
510 534
511/* 535/*
@@ -513,18 +537,18 @@ static short gc_psx_ddr_btn[] = { BTN_0, BTN_1, BTN_2, BTN_3 };
513 * the psx pad. 537 * the psx pad.
514 */ 538 */
515 539
516static void gc_psx_command(struct gc *gc, int b, unsigned char data[GC_MAX_DEVICES]) 540static void gc_psx_command(struct gc *gc, int b, unsigned char *data)
517{ 541{
542 struct parport *port = gc->pd->port;
518 int i, j, cmd, read; 543 int i, j, cmd, read;
519 544
520 for (i = 0; i < GC_MAX_DEVICES; i++) 545 memset(data, 0, GC_MAX_DEVICES);
521 data[i] = 0;
522 546
523 for (i = 0; i < GC_PSX_LENGTH; i++, b >>= 1) { 547 for (i = 0; i < GC_PSX_LENGTH; i++, b >>= 1) {
524 cmd = (b & 1) ? GC_PSX_COMMAND : 0; 548 cmd = (b & 1) ? GC_PSX_COMMAND : 0;
525 parport_write_data(gc->pd->port, cmd | GC_PSX_POWER); 549 parport_write_data(port, cmd | GC_PSX_POWER);
526 udelay(gc_psx_delay); 550 udelay(gc_psx_delay);
527 read = parport_read_status(gc->pd->port) ^ 0x80; 551 read = parport_read_status(port) ^ 0x80;
528 for (j = 0; j < GC_MAX_DEVICES; j++) 552 for (j = 0; j < GC_MAX_DEVICES; j++)
529 data[j] |= (read & gc_status_bit[j] & (gc->pads[GC_PSX] | gc->pads[GC_DDR])) ? (1 << i) : 0; 553 data[j] |= (read & gc_status_bit[j] & (gc->pads[GC_PSX] | gc->pads[GC_DDR])) ? (1 << i) : 0;
530 parport_write_data(gc->pd->port, cmd | GC_PSX_CLOCK | GC_PSX_POWER); 554 parport_write_data(gc->pd->port, cmd | GC_PSX_CLOCK | GC_PSX_POWER);
@@ -544,24 +568,29 @@ static void gc_psx_read_packet(struct gc *gc, unsigned char data[GC_MAX_DEVICES]
544 unsigned long flags; 568 unsigned long flags;
545 unsigned char data2[GC_MAX_DEVICES]; 569 unsigned char data2[GC_MAX_DEVICES];
546 570
547 parport_write_data(gc->pd->port, GC_PSX_CLOCK | GC_PSX_SELECT | GC_PSX_POWER); /* Select pad */ 571 /* Select pad */
572 parport_write_data(gc->pd->port, GC_PSX_CLOCK | GC_PSX_SELECT | GC_PSX_POWER);
548 udelay(gc_psx_delay); 573 udelay(gc_psx_delay);
549 parport_write_data(gc->pd->port, GC_PSX_CLOCK | GC_PSX_POWER); /* Deselect, begin command */ 574 /* Deselect, begin command */
575 parport_write_data(gc->pd->port, GC_PSX_CLOCK | GC_PSX_POWER);
550 udelay(gc_psx_delay); 576 udelay(gc_psx_delay);
551 577
552 local_irq_save(flags); 578 local_irq_save(flags);
553 579
554 gc_psx_command(gc, 0x01, data2); /* Access pad */ 580 gc_psx_command(gc, 0x01, data2); /* Access pad */
555 gc_psx_command(gc, 0x42, id); /* Get device ids */ 581 gc_psx_command(gc, 0x42, id); /* Get device ids */
556 gc_psx_command(gc, 0, data2); /* Dump status */ 582 gc_psx_command(gc, 0, data2); /* Dump status */
557 583
558 for (i =0; i < GC_MAX_DEVICES; i++) /* Find the longest pad */ 584 /* Find the longest pad */
559 if((gc_status_bit[i] & (gc->pads[GC_PSX] | gc->pads[GC_DDR])) 585 for (i = 0; i < GC_MAX_DEVICES; i++)
560 && (GC_PSX_LEN(id[i]) > max_len) 586 if ((gc_status_bit[i] & (gc->pads[GC_PSX] | gc->pads[GC_DDR])) &&
561 && (GC_PSX_LEN(id[i]) <= GC_PSX_BYTES)) 587 GC_PSX_LEN(id[i]) > max_len &&
588 GC_PSX_LEN(id[i]) <= GC_PSX_BYTES) {
562 max_len = GC_PSX_LEN(id[i]); 589 max_len = GC_PSX_LEN(id[i]);
590 }
563 591
564 for (i = 0; i < max_len; i++) { /* Read in all the data */ 592 /* Read in all the data */
593 for (i = 0; i < max_len; i++) {
565 gc_psx_command(gc, 0, data2); 594 gc_psx_command(gc, 0, data2);
566 for (j = 0; j < GC_MAX_DEVICES; j++) 595 for (j = 0; j < GC_MAX_DEVICES; j++)
567 data[j][i] = data2[j]; 596 data[j][i] = data2[j];
@@ -571,86 +600,99 @@ static void gc_psx_read_packet(struct gc *gc, unsigned char data[GC_MAX_DEVICES]
571 600
572 parport_write_data(gc->pd->port, GC_PSX_CLOCK | GC_PSX_SELECT | GC_PSX_POWER); 601 parport_write_data(gc->pd->port, GC_PSX_CLOCK | GC_PSX_SELECT | GC_PSX_POWER);
573 602
574 for(i = 0; i < GC_MAX_DEVICES; i++) /* Set id's to the real value */ 603 /* Set id's to the real value */
604 for (i = 0; i < GC_MAX_DEVICES; i++)
575 id[i] = GC_PSX_ID(id[i]); 605 id[i] = GC_PSX_ID(id[i]);
576} 606}
577 607
578static void gc_psx_process_packet(struct gc *gc) 608static void gc_psx_report_one(struct gc *gc, struct input_dev *dev,
609 unsigned char pad_type, unsigned char status_bit,
610 unsigned char *data)
579{ 611{
580 unsigned char data[GC_MAX_DEVICES][GC_PSX_BYTES]; 612 int i;
581 unsigned char id[GC_MAX_DEVICES];
582 struct input_dev *dev;
583 int i, j;
584 613
585 gc_psx_read_packet(gc, data, id); 614 switch (pad_type) {
586 615
587 for (i = 0; i < GC_MAX_DEVICES; i++) { 616 case GC_PSX_RUMBLE:
588 617
589 dev = gc->dev[i]; 618 input_report_key(dev, BTN_THUMBL, ~data[0] & 0x04);
590 if (!dev) 619 input_report_key(dev, BTN_THUMBR, ~data[0] & 0x02);
591 continue;
592 620
593 switch (id[i]) { 621 case GC_PSX_NEGCON:
622 case GC_PSX_ANALOG:
594 623
595 case GC_PSX_RUMBLE: 624 if (gc->pads[GC_DDR] & status_bit) {
625 for (i = 0; i < 4; i++)
626 input_report_key(dev, gc_psx_ddr_btn[i],
627 ~data[0] & (0x10 << i));
628 } else {
629 for (i = 0; i < 4; i++)
630 input_report_abs(dev, gc_psx_abs[i + 2],
631 data[i + 2]);
596 632
597 input_report_key(dev, BTN_THUMBL, ~data[i][0] & 0x04); 633 input_report_abs(dev, ABS_X, 128 + !(data[0] & 0x20) * 127 - !(data[0] & 0x80) * 128);
598 input_report_key(dev, BTN_THUMBR, ~data[i][0] & 0x02); 634 input_report_abs(dev, ABS_Y, 128 + !(data[0] & 0x40) * 127 - !(data[0] & 0x10) * 128);
635 }
599 636
600 case GC_PSX_NEGCON: 637 for (i = 0; i < 8; i++)
601 case GC_PSX_ANALOG: 638 input_report_key(dev, gc_psx_btn[i], ~data[1] & (1 << i));
602 639
603 if (gc->pads[GC_DDR] & gc_status_bit[i]) { 640 input_report_key(dev, BTN_START, ~data[0] & 0x08);
604 for(j = 0; j < 4; j++) 641 input_report_key(dev, BTN_SELECT, ~data[0] & 0x01);
605 input_report_key(dev, gc_psx_ddr_btn[j], ~data[i][0] & (0x10 << j));
606 } else {
607 for (j = 0; j < 4; j++)
608 input_report_abs(dev, gc_psx_abs[j + 2], data[i][j + 2]);
609 642
610 input_report_abs(dev, ABS_X, 128 + !(data[i][0] & 0x20) * 127 - !(data[i][0] & 0x80) * 128); 643 input_sync(dev);
611 input_report_abs(dev, ABS_Y, 128 + !(data[i][0] & 0x40) * 127 - !(data[i][0] & 0x10) * 128);
612 }
613 644
614 for (j = 0; j < 8; j++) 645 break;
615 input_report_key(dev, gc_psx_btn[j], ~data[i][1] & (1 << j));
616 646
617 input_report_key(dev, BTN_START, ~data[i][0] & 0x08); 647 case GC_PSX_NORMAL:
618 input_report_key(dev, BTN_SELECT, ~data[i][0] & 0x01); 648 if (gc->pads[GC_DDR] & status_bit) {
649 for (i = 0; i < 4; i++)
650 input_report_key(dev, gc_psx_ddr_btn[i],
651 ~data[0] & (0x10 << i));
652 } else {
653 input_report_abs(dev, ABS_X, 128 + !(data[0] & 0x20) * 127 - !(data[0] & 0x80) * 128);
654 input_report_abs(dev, ABS_Y, 128 + !(data[0] & 0x40) * 127 - !(data[0] & 0x10) * 128);
619 655
620 input_sync(dev); 656 /*
657 * For some reason if the extra axes are left unset
658 * they drift.
659 * for (i = 0; i < 4; i++)
660 input_report_abs(dev, gc_psx_abs[i + 2], 128);
661 * This needs to be debugged properly,
662 * maybe fuzz processing needs to be done
663 * in input_sync()
664 * --vojtech
665 */
666 }
621 667
622 break; 668 for (i = 0; i < 8; i++)
669 input_report_key(dev, gc_psx_btn[i], ~data[1] & (1 << i));
623 670
624 case GC_PSX_NORMAL: 671 input_report_key(dev, BTN_START, ~data[0] & 0x08);
625 if (gc->pads[GC_DDR] & gc_status_bit[i]) { 672 input_report_key(dev, BTN_SELECT, ~data[0] & 0x01);
626 for(j = 0; j < 4; j++)
627 input_report_key(dev, gc_psx_ddr_btn[j], ~data[i][0] & (0x10 << j));
628 } else {
629 input_report_abs(dev, ABS_X, 128 + !(data[i][0] & 0x20) * 127 - !(data[i][0] & 0x80) * 128);
630 input_report_abs(dev, ABS_Y, 128 + !(data[i][0] & 0x40) * 127 - !(data[i][0] & 0x10) * 128);
631 673
632 /* for some reason if the extra axes are left unset they drift */ 674 input_sync(dev);
633 /* for (j = 0; j < 4; j++) 675
634 input_report_abs(dev, gc_psx_abs[j + 2], 128); 676 break;
635 * This needs to be debugged properly,
636 * maybe fuzz processing needs to be done in input_sync()
637 * --vojtech
638 */
639 }
640 677
641 for (j = 0; j < 8; j++) 678 case 0: /* not a pad, ignore */
642 input_report_key(dev, gc_psx_btn[j], ~data[i][1] & (1 << j)); 679 break;
680 }
681}
643 682
644 input_report_key(dev, BTN_START, ~data[i][0] & 0x08); 683static void gc_psx_process_packet(struct gc *gc)
645 input_report_key(dev, BTN_SELECT, ~data[i][0] & 0x01); 684{
685 unsigned char data[GC_MAX_DEVICES][GC_PSX_BYTES];
686 unsigned char id[GC_MAX_DEVICES];
687 int i;
646 688
647 input_sync(dev); 689 gc_psx_read_packet(gc, data, id);
648 690
649 break; 691 for (i = 0; i < GC_MAX_DEVICES; i++) {
650 692
651 case 0: /* not a pad, ignore */ 693 if (gc->dev[i])
652 break; 694 gc_psx_report_one(gc, gc->dev[i],
653 } 695 id[i], gc_status_bit[i], data[i]);
654 } 696 }
655} 697}
656 698
@@ -770,60 +812,61 @@ static int __init gc_setup_pad(struct gc *gc, int idx, int pad_type)
770 812
771 switch (pad_type) { 813 switch (pad_type) {
772 814
773 case GC_N64: 815 case GC_N64:
774 for (i = 0; i < 10; i++) 816 for (i = 0; i < 10; i++)
775 set_bit(gc_n64_btn[i], input_dev->keybit); 817 __set_bit(gc_n64_btn[i], input_dev->keybit);
776
777 for (i = 0; i < 2; i++) {
778 input_set_abs_params(input_dev, ABS_X + i, -127, 126, 0, 2);
779 input_set_abs_params(input_dev, ABS_HAT0X + i, -1, 1, 0, 0);
780 }
781
782 err = gc_n64_init_ff(input_dev, idx);
783 if (err) {
784 printk(KERN_WARNING "gamecon.c: Failed to initiate rumble for N64 device %d\n", idx);
785 input_free_device(input_dev);
786 return err;
787 }
788
789 break;
790
791 case GC_SNESMOUSE:
792 set_bit(BTN_LEFT, input_dev->keybit);
793 set_bit(BTN_RIGHT, input_dev->keybit);
794 set_bit(REL_X, input_dev->relbit);
795 set_bit(REL_Y, input_dev->relbit);
796 break;
797
798 case GC_SNES:
799 for (i = 4; i < 8; i++)
800 set_bit(gc_snes_btn[i], input_dev->keybit);
801 case GC_NES:
802 for (i = 0; i < 4; i++)
803 set_bit(gc_snes_btn[i], input_dev->keybit);
804 break;
805 818
806 case GC_MULTI2: 819 for (i = 0; i < 2; i++) {
807 set_bit(BTN_THUMB, input_dev->keybit); 820 input_set_abs_params(input_dev, ABS_X + i, -127, 126, 0, 2);
808 case GC_MULTI: 821 input_set_abs_params(input_dev, ABS_HAT0X + i, -1, 1, 0, 0);
809 set_bit(BTN_TRIGGER, input_dev->keybit); 822 }
810 break;
811
812 case GC_PSX:
813 for (i = 0; i < 6; i++)
814 input_set_abs_params(input_dev, gc_psx_abs[i], 4, 252, 0, 2);
815 for (i = 0; i < 12; i++)
816 set_bit(gc_psx_btn[i], input_dev->keybit);
817
818 break;
819 823
820 case GC_DDR: 824 err = gc_n64_init_ff(input_dev, idx);
821 for (i = 0; i < 4; i++) 825 if (err) {
822 set_bit(gc_psx_ddr_btn[i], input_dev->keybit); 826 printk(KERN_WARNING "gamecon.c: Failed to initiate rumble for N64 device %d\n", idx);
823 for (i = 0; i < 12; i++) 827 input_free_device(input_dev);
824 set_bit(gc_psx_btn[i], input_dev->keybit); 828 return err;
829 }
825 830
826 break; 831 break;
832
833 case GC_SNESMOUSE:
834 __set_bit(BTN_LEFT, input_dev->keybit);
835 __set_bit(BTN_RIGHT, input_dev->keybit);
836 __set_bit(REL_X, input_dev->relbit);
837 __set_bit(REL_Y, input_dev->relbit);
838 break;
839
840 case GC_SNES:
841 for (i = 4; i < 8; i++)
842 __set_bit(gc_snes_btn[i], input_dev->keybit);
843 case GC_NES:
844 for (i = 0; i < 4; i++)
845 __set_bit(gc_snes_btn[i], input_dev->keybit);
846 break;
847
848 case GC_MULTI2:
849 __set_bit(BTN_THUMB, input_dev->keybit);
850 case GC_MULTI:
851 __set_bit(BTN_TRIGGER, input_dev->keybit);
852 break;
853
854 case GC_PSX:
855 for (i = 0; i < 6; i++)
856 input_set_abs_params(input_dev,
857 gc_psx_abs[i], 4, 252, 0, 2);
858 for (i = 0; i < 12; i++)
859 __set_bit(gc_psx_btn[i], input_dev->keybit);
860
861 break;
862
863 case GC_DDR:
864 for (i = 0; i < 4; i++)
865 __set_bit(gc_psx_ddr_btn[i], input_dev->keybit);
866 for (i = 0; i < 12; i++)
867 __set_bit(gc_psx_btn[i], input_dev->keybit);
868
869 break;
827 } 870 }
828 871
829 return 0; 872 return 0;
@@ -860,9 +903,7 @@ static struct gc __init *gc_probe(int parport, int *pads, int n_pads)
860 903
861 mutex_init(&gc->mutex); 904 mutex_init(&gc->mutex);
862 gc->pd = pd; 905 gc->pd = pd;
863 init_timer(&gc->timer); 906 setup_timer(&gc->timer, gc_timer, (long) gc);
864 gc->timer.data = (long) gc;
865 gc->timer.function = gc_timer;
866 907
867 for (i = 0; i < n_pads && i < GC_MAX_DEVICES; i++) { 908 for (i = 0; i < n_pads && i < GC_MAX_DEVICES; i++) {
868 if (!pads[i]) 909 if (!pads[i])