2 * $Id: analog.c,v 1.68 2002/01/22 20:18:32 vojtech Exp $
4 * Copyright (c) 1996-2001 Vojtech Pavlik
8 * Analog joystick and gamepad driver for Linux
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 * Should you need to contact me, the author, you can do so either by
27 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
28 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
31 #include <linux/config.h>
32 #include <linux/delay.h>
33 #include <linux/kernel.h>
34 #include <linux/module.h>
35 #include <linux/moduleparam.h>
36 #include <linux/slab.h>
37 #include <linux/bitops.h>
38 #include <linux/init.h>
39 #include <linux/input.h>
40 #include <linux/gameport.h>
41 #include <asm/timex.h>
43 #define DRIVER_DESC "Analog joystick and gamepad driver"
45 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
46 MODULE_DESCRIPTION(DRIVER_DESC
);
47 MODULE_LICENSE("GPL");
53 #define ANALOG_PORTS 16
55 static char *js
[ANALOG_PORTS
];
57 static int analog_options
[ANALOG_PORTS
];
58 module_param_array_named(map
, js
, charp
, &js_nargs
, 0);
59 MODULE_PARM_DESC(map
, "Describes analog joysticks type/capabilities");
61 __obsolete_setup("js=");
64 * Times, feature definitions.
67 #define ANALOG_RUDDER 0x00004
68 #define ANALOG_THROTTLE 0x00008
69 #define ANALOG_AXES_STD 0x0000f
70 #define ANALOG_BTNS_STD 0x000f0
72 #define ANALOG_BTNS_CHF 0x00100
73 #define ANALOG_HAT1_CHF 0x00200
74 #define ANALOG_HAT2_CHF 0x00400
75 #define ANALOG_HAT_FCS 0x00800
76 #define ANALOG_HATS_ALL 0x00e00
77 #define ANALOG_BTN_TL 0x01000
78 #define ANALOG_BTN_TR 0x02000
79 #define ANALOG_BTN_TL2 0x04000
80 #define ANALOG_BTN_TR2 0x08000
81 #define ANALOG_BTNS_TLR 0x03000
82 #define ANALOG_BTNS_TLR2 0x0c000
83 #define ANALOG_BTNS_GAMEPAD 0x0f000
85 #define ANALOG_HBTN_CHF 0x10000
86 #define ANALOG_ANY_CHF 0x10700
87 #define ANALOG_SAITEK 0x20000
88 #define ANALOG_EXTENSIONS 0x7ff00
89 #define ANALOG_GAMEPAD 0x80000
91 #define ANALOG_MAX_TIME 3 /* 3 ms */
92 #define ANALOG_LOOP_TIME 2000 /* 2 * loop */
93 #define ANALOG_SAITEK_DELAY 200 /* 200 us */
94 #define ANALOG_SAITEK_TIME 2000 /* 2000 us */
95 #define ANALOG_AXIS_TIME 2 /* 2 * refresh */
96 #define ANALOG_INIT_RETRIES 8 /* 8 times */
97 #define ANALOG_FUZZ_BITS 2 /* 2 bit more */
98 #define ANALOG_FUZZ_MAGIC 36 /* 36 u*ms/loop */
100 #define ANALOG_MAX_NAME_LENGTH 128
101 #define ANALOG_MAX_PHYS_LENGTH 32
103 static short analog_axes
[] = { ABS_X
, ABS_Y
, ABS_RUDDER
, ABS_THROTTLE
};
104 static short analog_hats
[] = { ABS_HAT0X
, ABS_HAT0Y
, ABS_HAT1X
, ABS_HAT1Y
, ABS_HAT2X
, ABS_HAT2Y
};
105 static short analog_pads
[] = { BTN_Y
, BTN_Z
, BTN_TL
, BTN_TR
};
106 static short analog_exts
[] = { ANALOG_HAT1_CHF
, ANALOG_HAT2_CHF
, ANALOG_HAT_FCS
};
107 static short analog_pad_btn
[] = { BTN_A
, BTN_B
, BTN_C
, BTN_X
, BTN_TL2
, BTN_TR2
, BTN_SELECT
, BTN_START
, BTN_MODE
, BTN_BASE
};
108 static short analog_joy_btn
[] = { BTN_TRIGGER
, BTN_THUMB
, BTN_TOP
, BTN_TOP2
, BTN_BASE
, BTN_BASE2
,
109 BTN_BASE3
, BTN_BASE4
, BTN_BASE5
, BTN_BASE6
};
111 static unsigned char analog_chf
[] = { 0xf, 0x0, 0x1, 0x9, 0x2, 0x4, 0xc, 0x8, 0x3, 0x5, 0xb, 0x7, 0xd, 0xe, 0xa, 0x6 };
114 struct input_dev dev
;
117 char name
[ANALOG_MAX_NAME_LENGTH
];
118 char phys
[ANALOG_MAX_PHYS_LENGTH
];
122 struct gameport
*gameport
;
123 struct analog analog
[2];
143 #define GET_TIME(x) do { if (cpu_has_tsc) rdtscl(x); else x = get_time_pit(); } while (0)
144 #define DELTA(x,y) (cpu_has_tsc ? ((y) - (x)) : ((x) - (y) + ((x) < (y) ? CLOCK_TICK_RATE / HZ : 0)))
145 #define TIME_NAME (cpu_has_tsc?"TSC":"PIT")
146 static unsigned int get_time_pit(void)
148 extern spinlock_t i8253_lock
;
152 spin_lock_irqsave(&i8253_lock
, flags
);
155 count
|= inb_p(0x40) << 8;
156 spin_unlock_irqrestore(&i8253_lock
, flags
);
160 #elif defined(__x86_64__)
161 #define GET_TIME(x) rdtscl(x)
162 #define DELTA(x,y) ((y)-(x))
163 #define TIME_NAME "TSC"
164 #elif defined(__alpha__)
165 #define GET_TIME(x) do { x = get_cycles(); } while (0)
166 #define DELTA(x,y) ((y)-(x))
167 #define TIME_NAME "PCC"
170 static unsigned long analog_faketime
= 0;
171 #define GET_TIME(x) do { x = analog_faketime++; } while(0)
172 #define DELTA(x,y) ((y)-(x))
173 #define TIME_NAME "Unreliable"
174 #warning Precise timer not defined for this architecture.
178 * analog_decode() decodes analog joystick data and reports input events.
181 static void analog_decode(struct analog
*analog
, int *axes
, int *initial
, int buttons
)
183 struct input_dev
*dev
= &analog
->dev
;
186 if (analog
->mask
& ANALOG_HAT_FCS
)
187 for (i
= 0; i
< 4; i
++)
188 if (axes
[3] < ((initial
[3] * ((i
<< 1) + 1)) >> 3)) {
189 buttons
|= 1 << (i
+ 14);
193 for (i
= j
= 0; i
< 6; i
++)
194 if (analog
->mask
& (0x10 << i
))
195 input_report_key(dev
, analog
->buttons
[j
++], (buttons
>> i
) & 1);
197 if (analog
->mask
& ANALOG_HBTN_CHF
)
198 for (i
= 0; i
< 4; i
++)
199 input_report_key(dev
, analog
->buttons
[j
++], (buttons
>> (i
+ 10)) & 1);
201 if (analog
->mask
& ANALOG_BTN_TL
)
202 input_report_key(dev
, analog_pads
[0], axes
[2] < (initial
[2] >> 1));
203 if (analog
->mask
& ANALOG_BTN_TR
)
204 input_report_key(dev
, analog_pads
[1], axes
[3] < (initial
[3] >> 1));
205 if (analog
->mask
& ANALOG_BTN_TL2
)
206 input_report_key(dev
, analog_pads
[2], axes
[2] > (initial
[2] + (initial
[2] >> 1)));
207 if (analog
->mask
& ANALOG_BTN_TR2
)
208 input_report_key(dev
, analog_pads
[3], axes
[3] > (initial
[3] + (initial
[3] >> 1)));
210 for (i
= j
= 0; i
< 4; i
++)
211 if (analog
->mask
& (1 << i
))
212 input_report_abs(dev
, analog_axes
[j
++], axes
[i
]);
214 for (i
= j
= 0; i
< 3; i
++)
215 if (analog
->mask
& analog_exts
[i
]) {
216 input_report_abs(dev
, analog_hats
[j
++],
217 ((buttons
>> ((i
<< 2) + 7)) & 1) - ((buttons
>> ((i
<< 2) + 9)) & 1));
218 input_report_abs(dev
, analog_hats
[j
++],
219 ((buttons
>> ((i
<< 2) + 8)) & 1) - ((buttons
>> ((i
<< 2) + 6)) & 1));
226 * analog_cooked_read() reads analog joystick data.
229 static int analog_cooked_read(struct analog_port
*port
)
231 struct gameport
*gameport
= port
->gameport
;
232 unsigned int time
[4], start
, loop
, now
, loopout
, timeout
;
233 unsigned char data
[4], this, last
;
237 loopout
= (ANALOG_LOOP_TIME
* port
->loop
) / 1000;
238 timeout
= ANALOG_MAX_TIME
* port
->speed
;
240 local_irq_save(flags
);
241 gameport_trigger(gameport
);
243 local_irq_restore(flags
);
254 this = gameport_read(gameport
) & port
->mask
;
256 local_irq_restore(flags
);
258 if ((last
^ this) && (DELTA(loop
, now
) < loopout
)) {
259 data
[i
] = last
^ this;
264 } while (this && (i
< 4) && (DELTA(start
, now
) < timeout
));
268 for (--i
; i
>= 0; i
--) {
270 for (j
= 0; j
< 4; j
++)
271 if (data
[i
] & (1 << j
))
272 port
->axes
[j
] = (DELTA(start
, time
[i
]) << ANALOG_FUZZ_BITS
) / port
->loop
;
275 return -(this != port
->mask
);
278 static int analog_button_read(struct analog_port
*port
, char saitek
, char chf
)
282 int strobe
= gameport_time(port
->gameport
, ANALOG_SAITEK_TIME
);
284 u
= gameport_read(port
->gameport
);
287 port
->buttons
= (~u
>> 4) & 0xf;
293 while ((~u
& 0xf0) && (i
< 16) && t
) {
294 port
->buttons
|= 1 << analog_chf
[(~u
>> 4) & 0xf];
295 if (!saitek
) return 0;
296 udelay(ANALOG_SAITEK_DELAY
);
298 gameport_trigger(port
->gameport
);
299 while (((u
= gameport_read(port
->gameport
)) & port
->mask
) && t
) t
--;
303 return -(!t
|| (i
== 16));
307 * analog_poll() repeatedly polls the Analog joysticks.
310 static void analog_poll(struct gameport
*gameport
)
312 struct analog_port
*port
= gameport_get_drvdata(gameport
);
315 char saitek
= !!(port
->analog
[0].mask
& ANALOG_SAITEK
);
316 char chf
= !!(port
->analog
[0].mask
& ANALOG_ANY_CHF
);
319 port
->bads
-= gameport_cooked_read(port
->gameport
, port
->axes
, &port
->buttons
);
321 port
->buttons
= port
->buttons
? (1 << analog_chf
[port
->buttons
]) : 0;
324 if (!port
->axtime
--) {
325 port
->bads
-= analog_cooked_read(port
);
326 port
->bads
-= analog_button_read(port
, saitek
, chf
);
328 port
->axtime
= ANALOG_AXIS_TIME
- 1;
331 analog_button_read(port
, saitek
, chf
);
335 for (i
= 0; i
< 2; i
++)
336 if (port
->analog
[i
].mask
)
337 analog_decode(port
->analog
+ i
, port
->axes
, port
->initial
, port
->buttons
);
341 * analog_open() is a callback from the input open routine.
344 static int analog_open(struct input_dev
*dev
)
346 struct analog_port
*port
= dev
->private;
348 gameport_start_polling(port
->gameport
);
353 * analog_close() is a callback from the input close routine.
356 static void analog_close(struct input_dev
*dev
)
358 struct analog_port
*port
= dev
->private;
360 gameport_stop_polling(port
->gameport
);
364 * analog_calibrate_timer() calibrates the timer and computes loop
365 * and timeout values for a joystick port.
368 static void analog_calibrate_timer(struct analog_port
*port
)
370 struct gameport
*gameport
= port
->gameport
;
371 unsigned int i
, t
, tx
, t1
, t2
, t3
;
374 local_irq_save(flags
);
377 analog_faketime
+= 830;
382 local_irq_restore(flags
);
384 port
->speed
= DELTA(t1
, t2
) - DELTA(t2
, t3
);
388 for (i
= 0; i
< 50; i
++) {
389 local_irq_save(flags
);
391 for (t
= 0; t
< 50; t
++) { gameport_read(gameport
); GET_TIME(t2
); }
393 local_irq_restore(flags
);
395 t
= DELTA(t1
, t2
) - DELTA(t2
, t3
);
399 port
->loop
= tx
/ 50;
403 * analog_name() constructs a name for an analog joystick.
406 static void analog_name(struct analog
*analog
)
408 sprintf(analog
->name
, "Analog %d-axis %d-button",
409 hweight8(analog
->mask
& ANALOG_AXES_STD
),
410 hweight8(analog
->mask
& ANALOG_BTNS_STD
) + !!(analog
->mask
& ANALOG_BTNS_CHF
) * 2 +
411 hweight16(analog
->mask
& ANALOG_BTNS_GAMEPAD
) + !!(analog
->mask
& ANALOG_HBTN_CHF
) * 4);
413 if (analog
->mask
& ANALOG_HATS_ALL
)
414 sprintf(analog
->name
, "%s %d-hat",
415 analog
->name
, hweight16(analog
->mask
& ANALOG_HATS_ALL
));
417 if (analog
->mask
& ANALOG_HAT_FCS
)
418 strcat(analog
->name
, " FCS");
419 if (analog
->mask
& ANALOG_ANY_CHF
)
420 strcat(analog
->name
, (analog
->mask
& ANALOG_SAITEK
) ? " Saitek" : " CHF");
422 strcat(analog
->name
, (analog
->mask
& ANALOG_GAMEPAD
) ? " gamepad": " joystick");
426 * analog_init_device()
429 static void analog_init_device(struct analog_port
*port
, struct analog
*analog
, int index
)
431 int i
, j
, t
, v
, w
, x
, y
, z
;
434 sprintf(analog
->phys
, "%s/input%d", port
->gameport
->phys
, index
);
435 analog
->buttons
= (analog
->mask
& ANALOG_GAMEPAD
) ? analog_pad_btn
: analog_joy_btn
;
437 init_input_dev(&analog
->dev
);
439 analog
->dev
.name
= analog
->name
;
440 analog
->dev
.phys
= analog
->phys
;
441 analog
->dev
.id
.bustype
= BUS_GAMEPORT
;
442 analog
->dev
.id
.vendor
= GAMEPORT_ID_VENDOR_ANALOG
;
443 analog
->dev
.id
.product
= analog
->mask
>> 4;
444 analog
->dev
.id
.version
= 0x0100;
446 analog
->dev
.open
= analog_open
;
447 analog
->dev
.close
= analog_close
;
448 analog
->dev
.private = port
;
449 analog
->dev
.evbit
[0] = BIT(EV_KEY
) | BIT(EV_ABS
);
451 for (i
= j
= 0; i
< 4; i
++)
452 if (analog
->mask
& (1 << i
)) {
456 y
= (port
->axes
[0] + port
->axes
[1]) >> 1;
457 z
= y
- port
->axes
[i
];
462 set_bit(t
, analog
->dev
.absbit
);
464 if ((i
== 2 || i
== 3) && (j
== 2 || j
== 3) && (z
> (y
>> 3)))
467 if (analog
->mask
& ANALOG_SAITEK
) {
468 if (i
== 2) x
= port
->axes
[i
];
473 analog
->dev
.absmax
[t
] = (x
<< 1) - v
;
474 analog
->dev
.absmin
[t
] = v
;
475 analog
->dev
.absfuzz
[t
] = port
->fuzz
;
476 analog
->dev
.absflat
[t
] = w
;
481 for (i
= j
= 0; i
< 3; i
++)
482 if (analog
->mask
& analog_exts
[i
])
483 for (x
= 0; x
< 2; x
++) {
484 t
= analog_hats
[j
++];
485 set_bit(t
, analog
->dev
.absbit
);
486 analog
->dev
.absmax
[t
] = 1;
487 analog
->dev
.absmin
[t
] = -1;
490 for (i
= j
= 0; i
< 4; i
++)
491 if (analog
->mask
& (0x10 << i
))
492 set_bit(analog
->buttons
[j
++], analog
->dev
.keybit
);
494 if (analog
->mask
& ANALOG_BTNS_CHF
)
495 for (i
= 0; i
< 2; i
++)
496 set_bit(analog
->buttons
[j
++], analog
->dev
.keybit
);
498 if (analog
->mask
& ANALOG_HBTN_CHF
)
499 for (i
= 0; i
< 4; i
++)
500 set_bit(analog
->buttons
[j
++], analog
->dev
.keybit
);
502 for (i
= 0; i
< 4; i
++)
503 if (analog
->mask
& (ANALOG_BTN_TL
<< i
))
504 set_bit(analog_pads
[i
], analog
->dev
.keybit
);
506 analog_decode(analog
, port
->axes
, port
->initial
, port
->buttons
);
508 input_register_device(&analog
->dev
);
510 printk(KERN_INFO
"input: %s at %s", analog
->name
, port
->gameport
->phys
);
513 printk(" [ADC port]\n");
515 printk(" [%s timer, %d %sHz clock, %d ns res]\n", TIME_NAME
,
516 port
->speed
> 10000 ? (port
->speed
+ 800) / 1000 : port
->speed
,
517 port
->speed
> 10000 ? "M" : "k",
518 port
->speed
> 10000 ? (port
->loop
* 1000) / (port
->speed
/ 1000)
519 : (port
->loop
* 1000000) / port
->speed
);
523 * analog_init_devices() sets up device-specific values and registers the input devices.
526 static int analog_init_masks(struct analog_port
*port
)
529 struct analog
*analog
= port
->analog
;
535 if ((port
->mask
& 3) != 3 && port
->mask
!= 0xc) {
536 printk(KERN_WARNING
"analog.c: Unknown joystick device found "
537 "(data=%#x, %s), probably not analog joystick.\n",
538 port
->mask
, port
->gameport
->phys
);
543 i
= analog_options
[0]; /* FIXME !!! - need to specify options for different ports */
545 analog
[0].mask
= i
& 0xfffff;
547 analog
[0].mask
&= ~(ANALOG_AXES_STD
| ANALOG_HAT_FCS
| ANALOG_BTNS_GAMEPAD
)
548 | port
->mask
| ((port
->mask
<< 8) & ANALOG_HAT_FCS
)
549 | ((port
->mask
<< 10) & ANALOG_BTNS_TLR
) | ((port
->mask
<< 12) & ANALOG_BTNS_TLR2
);
551 analog
[0].mask
&= ~(ANALOG_HAT2_CHF
)
552 | ((analog
[0].mask
& ANALOG_HBTN_CHF
) ? 0 : ANALOG_HAT2_CHF
);
554 analog
[0].mask
&= ~(ANALOG_THROTTLE
| ANALOG_BTN_TR
| ANALOG_BTN_TR2
)
555 | ((~analog
[0].mask
& ANALOG_HAT_FCS
) >> 8)
556 | ((~analog
[0].mask
& ANALOG_HAT_FCS
) << 2)
557 | ((~analog
[0].mask
& ANALOG_HAT_FCS
) << 4);
559 analog
[0].mask
&= ~(ANALOG_THROTTLE
| ANALOG_RUDDER
)
560 | (((~analog
[0].mask
& ANALOG_BTNS_TLR
) >> 10)
561 & ((~analog
[0].mask
& ANALOG_BTNS_TLR2
) >> 12));
563 analog
[1].mask
= ((i
>> 20) & 0xff) | ((i
>> 12) & 0xf0000);
565 analog
[1].mask
&= (analog
[0].mask
& ANALOG_EXTENSIONS
) ? ANALOG_GAMEPAD
566 : (((ANALOG_BTNS_STD
| port
->mask
) & ~analog
[0].mask
) | ANALOG_GAMEPAD
);
570 for (i
= 0; i
< 4; i
++) max
[i
] = port
->axes
[i
] << 1;
572 if ((analog
[0].mask
& 0x7) == 0x7) max
[2] = (max
[0] + max
[1]) >> 1;
573 if ((analog
[0].mask
& 0xb) == 0xb) max
[3] = (max
[0] + max
[1]) >> 1;
574 if ((analog
[0].mask
& ANALOG_BTN_TL
) && !(analog
[0].mask
& ANALOG_BTN_TL2
)) max
[2] >>= 1;
575 if ((analog
[0].mask
& ANALOG_BTN_TR
) && !(analog
[0].mask
& ANALOG_BTN_TR2
)) max
[3] >>= 1;
576 if ((analog
[0].mask
& ANALOG_HAT_FCS
)) max
[3] >>= 1;
578 gameport_calibrate(port
->gameport
, port
->axes
, max
);
581 for (i
= 0; i
< 4; i
++)
582 port
->initial
[i
] = port
->axes
[i
];
584 return -!(analog
[0].mask
|| analog
[1].mask
);
587 static int analog_init_port(struct gameport
*gameport
, struct gameport_driver
*drv
, struct analog_port
*port
)
591 port
->gameport
= gameport
;
593 gameport_set_drvdata(gameport
, port
);
595 if (!gameport_open(gameport
, drv
, GAMEPORT_MODE_RAW
)) {
597 analog_calibrate_timer(port
);
599 gameport_trigger(gameport
);
600 t
= gameport_read(gameport
);
601 msleep(ANALOG_MAX_TIME
);
602 port
->mask
= (gameport_read(gameport
) ^ t
) & t
& 0xf;
603 port
->fuzz
= (port
->speed
* ANALOG_FUZZ_MAGIC
) / port
->loop
/ 1000 + ANALOG_FUZZ_BITS
;
605 for (i
= 0; i
< ANALOG_INIT_RETRIES
; i
++) {
606 if (!analog_cooked_read(port
))
608 msleep(ANALOG_MAX_TIME
);
613 msleep(ANALOG_MAX_TIME
);
614 t
= gameport_time(gameport
, ANALOG_MAX_TIME
* 1000);
615 gameport_trigger(gameport
);
616 while ((gameport_read(port
->gameport
) & port
->mask
) && (u
< t
))
618 udelay(ANALOG_SAITEK_DELAY
);
619 t
= gameport_time(gameport
, ANALOG_SAITEK_TIME
);
620 gameport_trigger(gameport
);
621 while ((gameport_read(port
->gameport
) & port
->mask
) && (v
< t
))
624 if (v
< (u
>> 1)) { /* FIXME - more than one port */
625 analog_options
[0] |= /* FIXME - more than one port */
626 ANALOG_SAITEK
| ANALOG_BTNS_CHF
| ANALOG_HBTN_CHF
| ANALOG_HAT1_CHF
;
630 gameport_close(gameport
);
633 if (!gameport_open(gameport
, drv
, GAMEPORT_MODE_COOKED
)) {
635 for (i
= 0; i
< ANALOG_INIT_RETRIES
; i
++)
636 if (!gameport_cooked_read(gameport
, port
->axes
, &port
->buttons
))
638 for (i
= 0; i
< 4; i
++)
639 if (port
->axes
[i
] != -1)
640 port
->mask
|= 1 << i
;
642 port
->fuzz
= gameport
->fuzz
;
647 return gameport_open(gameport
, drv
, GAMEPORT_MODE_RAW
);
650 static int analog_connect(struct gameport
*gameport
, struct gameport_driver
*drv
)
652 struct analog_port
*port
;
656 if (!(port
= kcalloc(1, sizeof(struct analog_port
), GFP_KERNEL
)))
659 err
= analog_init_port(gameport
, drv
, port
);
665 err
= analog_init_masks(port
);
667 gameport_close(gameport
);
668 gameport_set_drvdata(gameport
, NULL
);
673 gameport_set_poll_handler(gameport
, analog_poll
);
674 gameport_set_poll_interval(gameport
, 10);
676 for (i
= 0; i
< 2; i
++)
677 if (port
->analog
[i
].mask
)
678 analog_init_device(port
, port
->analog
+ i
, i
);
683 static void analog_disconnect(struct gameport
*gameport
)
686 struct analog_port
*port
= gameport_get_drvdata(gameport
);
688 for (i
= 0; i
< 2; i
++)
689 if (port
->analog
[i
].mask
)
690 input_unregister_device(&port
->analog
[i
].dev
);
691 gameport_close(gameport
);
692 gameport_set_drvdata(gameport
, NULL
);
693 printk(KERN_INFO
"analog.c: %d out of %d reads (%d%%) on %s failed\n",
694 port
->bads
, port
->reads
, port
->reads
? (port
->bads
* 100 / port
->reads
) : 0,
695 port
->gameport
->phys
);
699 struct analog_types
{
704 static struct analog_types analog_types
[] = {
705 { "none", 0x00000000 },
706 { "auto", 0x000000ff },
707 { "2btn", 0x0000003f },
708 { "y-joy", 0x0cc00033 },
709 { "y-pad", 0x8cc80033 },
710 { "fcs", 0x000008f7 },
711 { "chf", 0x000002ff },
712 { "fullchf", 0x000007ff },
713 { "gamepad", 0x000830f3 },
714 { "gamepad8", 0x0008f0f3 },
718 static void analog_parse_options(void)
723 for (i
= 0; i
< js_nargs
; i
++) {
725 for (j
= 0; analog_types
[j
].name
; j
++)
726 if (!strcmp(analog_types
[j
].name
, js
[i
])) {
727 analog_options
[i
] = analog_types
[j
].value
;
730 if (analog_types
[j
].name
) continue;
732 analog_options
[i
] = simple_strtoul(js
[i
], &end
, 0);
733 if (end
!= js
[i
]) continue;
735 analog_options
[i
] = 0xff;
736 if (!strlen(js
[i
])) continue;
738 printk(KERN_WARNING
"analog.c: Bad config for port %d - \"%s\"\n", i
, js
[i
]);
741 for (; i
< ANALOG_PORTS
; i
++)
742 analog_options
[i
] = 0xff;
746 * The gameport device structure.
749 static struct gameport_driver analog_drv
= {
753 .description
= DRIVER_DESC
,
754 .connect
= analog_connect
,
755 .disconnect
= analog_disconnect
,
758 static int __init
analog_init(void)
760 analog_parse_options();
761 gameport_register_driver(&analog_drv
);
766 static void __exit
analog_exit(void)
768 gameport_unregister_driver(&analog_drv
);
771 module_init(analog_init
);
772 module_exit(analog_exit
);