1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) 1996-2001 Vojtech Pavlik
7 * Analog joystick and gamepad driver for Linux
13 #include <linux/delay.h>
14 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/slab.h>
17 #include <linux/bitops.h>
18 #include <linux/init.h>
19 #include <linux/input.h>
20 #include <linux/gameport.h>
21 #include <linux/jiffies.h>
22 #include <linux/timex.h>
23 #include <linux/timekeeping.h>
25 #define DRIVER_DESC "Analog joystick and gamepad driver"
27 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
28 MODULE_DESCRIPTION(DRIVER_DESC
);
29 MODULE_LICENSE("GPL");
31 static bool use_ktime
= true;
32 module_param(use_ktime
, bool, 0400);
33 MODULE_PARM_DESC(use_ktime
, "Use ktime for measuring I/O speed");
39 #define ANALOG_PORTS 16
41 static char *js
[ANALOG_PORTS
];
42 static unsigned int js_nargs
;
43 static int analog_options
[ANALOG_PORTS
];
44 module_param_array_named(map
, js
, charp
, &js_nargs
, 0);
45 MODULE_PARM_DESC(map
, "Describes analog joysticks type/capabilities");
48 * Times, feature definitions.
51 #define ANALOG_RUDDER 0x00004
52 #define ANALOG_THROTTLE 0x00008
53 #define ANALOG_AXES_STD 0x0000f
54 #define ANALOG_BTNS_STD 0x000f0
56 #define ANALOG_BTNS_CHF 0x00100
57 #define ANALOG_HAT1_CHF 0x00200
58 #define ANALOG_HAT2_CHF 0x00400
59 #define ANALOG_HAT_FCS 0x00800
60 #define ANALOG_HATS_ALL 0x00e00
61 #define ANALOG_BTN_TL 0x01000
62 #define ANALOG_BTN_TR 0x02000
63 #define ANALOG_BTN_TL2 0x04000
64 #define ANALOG_BTN_TR2 0x08000
65 #define ANALOG_BTNS_TLR 0x03000
66 #define ANALOG_BTNS_TLR2 0x0c000
67 #define ANALOG_BTNS_GAMEPAD 0x0f000
69 #define ANALOG_HBTN_CHF 0x10000
70 #define ANALOG_ANY_CHF 0x10700
71 #define ANALOG_SAITEK 0x20000
72 #define ANALOG_EXTENSIONS 0x7ff00
73 #define ANALOG_GAMEPAD 0x80000
75 #define ANALOG_MAX_TIME 3 /* 3 ms */
76 #define ANALOG_LOOP_TIME 2000 /* 2 * loop */
77 #define ANALOG_SAITEK_DELAY 200 /* 200 us */
78 #define ANALOG_SAITEK_TIME 2000 /* 2000 us */
79 #define ANALOG_AXIS_TIME 2 /* 2 * refresh */
80 #define ANALOG_INIT_RETRIES 8 /* 8 times */
81 #define ANALOG_FUZZ_BITS 2 /* 2 bit more */
82 #define ANALOG_FUZZ_MAGIC 36 /* 36 u*ms/loop */
84 #define ANALOG_MAX_NAME_LENGTH 128
85 #define ANALOG_MAX_PHYS_LENGTH 32
87 static short analog_axes
[] = { ABS_X
, ABS_Y
, ABS_RUDDER
, ABS_THROTTLE
};
88 static short analog_hats
[] = { ABS_HAT0X
, ABS_HAT0Y
, ABS_HAT1X
, ABS_HAT1Y
, ABS_HAT2X
, ABS_HAT2Y
};
89 static short analog_pads
[] = { BTN_Y
, BTN_Z
, BTN_TL
, BTN_TR
};
90 static short analog_exts
[] = { ANALOG_HAT1_CHF
, ANALOG_HAT2_CHF
, ANALOG_HAT_FCS
};
91 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
};
92 static short analog_joy_btn
[] = { BTN_TRIGGER
, BTN_THUMB
, BTN_TOP
, BTN_TOP2
, BTN_BASE
, BTN_BASE2
,
93 BTN_BASE3
, BTN_BASE4
, BTN_BASE5
, BTN_BASE6
};
95 static unsigned char analog_chf
[] = { 0xf, 0x0, 0x1, 0x9, 0x2, 0x4, 0xc, 0x8, 0x3, 0x5, 0xb, 0x7, 0xd, 0xe, 0xa, 0x6 };
98 struct input_dev
*dev
;
101 char name
[ANALOG_MAX_NAME_LENGTH
];
102 char phys
[ANALOG_MAX_PHYS_LENGTH
];
106 struct gameport
*gameport
;
107 struct analog analog
[2];
128 #include <linux/i8253.h>
130 #define GET_TIME(x) do { if (boot_cpu_has(X86_FEATURE_TSC)) x = (unsigned int)rdtsc(); else x = get_time_pit(); } while (0)
131 #define DELTA(x,y) (boot_cpu_has(X86_FEATURE_TSC) ? ((y) - (x)) : ((x) - (y) + ((x) < (y) ? PIT_TICK_RATE / HZ : 0)))
132 #define TIME_NAME (boot_cpu_has(X86_FEATURE_TSC)?"TSC":"PIT")
133 static unsigned int get_time_pit(void)
138 raw_spin_lock_irqsave(&i8253_lock
, flags
);
141 count
|= inb_p(0x40) << 8;
142 raw_spin_unlock_irqrestore(&i8253_lock
, flags
);
146 #elif defined(__x86_64__)
147 #define GET_TIME(x) do { x = (unsigned int)rdtsc(); } while (0)
148 #define DELTA(x,y) ((y)-(x))
149 #define TIME_NAME "TSC"
150 #elif defined(__alpha__) || defined(CONFIG_ARM) || defined(CONFIG_ARM64) || defined(CONFIG_PPC) || defined(CONFIG_RISCV)
151 #define GET_TIME(x) do { x = get_cycles(); } while (0)
152 #define DELTA(x,y) ((y)-(x))
153 #define TIME_NAME "get_cycles"
156 static unsigned long analog_faketime
= 0;
157 #define GET_TIME(x) do { x = analog_faketime++; } while(0)
158 #define DELTA(x,y) ((y)-(x))
159 #define TIME_NAME "Unreliable"
160 #warning Precise timer not defined for this architecture.
163 static inline u64
get_time(void)
166 return ktime_get_ns();
174 static inline unsigned int delta(u64 x
, u64 y
)
179 return DELTA((unsigned int)x
, (unsigned int)y
);
183 * analog_decode() decodes analog joystick data and reports input events.
186 static void analog_decode(struct analog
*analog
, int *axes
, int *initial
, int buttons
)
188 struct input_dev
*dev
= analog
->dev
;
191 if (analog
->mask
& ANALOG_HAT_FCS
)
192 for (i
= 0; i
< 4; i
++)
193 if (axes
[3] < ((initial
[3] * ((i
<< 1) + 1)) >> 3)) {
194 buttons
|= 1 << (i
+ 14);
198 for (i
= j
= 0; i
< 6; i
++)
199 if (analog
->mask
& (0x10 << i
))
200 input_report_key(dev
, analog
->buttons
[j
++], (buttons
>> i
) & 1);
202 if (analog
->mask
& ANALOG_HBTN_CHF
)
203 for (i
= 0; i
< 4; i
++)
204 input_report_key(dev
, analog
->buttons
[j
++], (buttons
>> (i
+ 10)) & 1);
206 if (analog
->mask
& ANALOG_BTN_TL
)
207 input_report_key(dev
, analog_pads
[0], axes
[2] < (initial
[2] >> 1));
208 if (analog
->mask
& ANALOG_BTN_TR
)
209 input_report_key(dev
, analog_pads
[1], axes
[3] < (initial
[3] >> 1));
210 if (analog
->mask
& ANALOG_BTN_TL2
)
211 input_report_key(dev
, analog_pads
[2], axes
[2] > (initial
[2] + (initial
[2] >> 1)));
212 if (analog
->mask
& ANALOG_BTN_TR2
)
213 input_report_key(dev
, analog_pads
[3], axes
[3] > (initial
[3] + (initial
[3] >> 1)));
215 for (i
= j
= 0; i
< 4; i
++)
216 if (analog
->mask
& (1 << i
))
217 input_report_abs(dev
, analog_axes
[j
++], axes
[i
]);
219 for (i
= j
= 0; i
< 3; i
++)
220 if (analog
->mask
& analog_exts
[i
]) {
221 input_report_abs(dev
, analog_hats
[j
++],
222 ((buttons
>> ((i
<< 2) + 7)) & 1) - ((buttons
>> ((i
<< 2) + 9)) & 1));
223 input_report_abs(dev
, analog_hats
[j
++],
224 ((buttons
>> ((i
<< 2) + 8)) & 1) - ((buttons
>> ((i
<< 2) + 6)) & 1));
231 * analog_cooked_read() reads analog joystick data.
234 static int analog_cooked_read(struct analog_port
*port
)
236 struct gameport
*gameport
= port
->gameport
;
237 u64 time
[4], start
, loop
, now
;
238 unsigned int loopout
, timeout
;
239 unsigned char data
[4], this, last
;
243 loopout
= (ANALOG_LOOP_TIME
* port
->loop
) / 1000;
244 timeout
= ANALOG_MAX_TIME
* port
->speed
;
246 local_irq_save(flags
);
247 gameport_trigger(gameport
);
249 local_irq_restore(flags
);
260 this = gameport_read(gameport
) & port
->mask
;
262 local_irq_restore(flags
);
264 if ((last
^ this) && (delta(loop
, now
) < loopout
)) {
265 data
[i
] = last
^ this;
270 } while (this && (i
< 4) && (delta(start
, now
) < timeout
));
274 for (--i
; i
>= 0; i
--) {
276 for (j
= 0; j
< 4; j
++)
277 if (data
[i
] & (1 << j
))
278 port
->axes
[j
] = (delta(start
, time
[i
]) << ANALOG_FUZZ_BITS
) / port
->loop
;
281 return -(this != port
->mask
);
284 static int analog_button_read(struct analog_port
*port
, char saitek
, char chf
)
288 int strobe
= gameport_time(port
->gameport
, ANALOG_SAITEK_TIME
);
290 u
= gameport_read(port
->gameport
);
293 port
->buttons
= (~u
>> 4) & 0xf;
299 while ((~u
& 0xf0) && (i
< 16) && t
) {
300 port
->buttons
|= 1 << analog_chf
[(~u
>> 4) & 0xf];
301 if (!saitek
) return 0;
302 udelay(ANALOG_SAITEK_DELAY
);
304 gameport_trigger(port
->gameport
);
305 while (((u
= gameport_read(port
->gameport
)) & port
->mask
) && t
) t
--;
309 return -(!t
|| (i
== 16));
313 * analog_poll() repeatedly polls the Analog joysticks.
316 static void analog_poll(struct gameport
*gameport
)
318 struct analog_port
*port
= gameport_get_drvdata(gameport
);
321 char saitek
= !!(port
->analog
[0].mask
& ANALOG_SAITEK
);
322 char chf
= !!(port
->analog
[0].mask
& ANALOG_ANY_CHF
);
325 port
->bads
-= gameport_cooked_read(port
->gameport
, port
->axes
, &port
->buttons
);
327 port
->buttons
= port
->buttons
? (1 << analog_chf
[port
->buttons
]) : 0;
330 if (!port
->axtime
--) {
331 port
->bads
-= analog_cooked_read(port
);
332 port
->bads
-= analog_button_read(port
, saitek
, chf
);
334 port
->axtime
= ANALOG_AXIS_TIME
- 1;
337 analog_button_read(port
, saitek
, chf
);
341 for (i
= 0; i
< 2; i
++)
342 if (port
->analog
[i
].mask
)
343 analog_decode(port
->analog
+ i
, port
->axes
, port
->initial
, port
->buttons
);
347 * analog_open() is a callback from the input open routine.
350 static int analog_open(struct input_dev
*dev
)
352 struct analog_port
*port
= input_get_drvdata(dev
);
354 gameport_start_polling(port
->gameport
);
359 * analog_close() is a callback from the input close routine.
362 static void analog_close(struct input_dev
*dev
)
364 struct analog_port
*port
= input_get_drvdata(dev
);
366 gameport_stop_polling(port
->gameport
);
370 * analog_calibrate_timer() calibrates the timer and computes loop
371 * and timeout values for a joystick port.
374 static void analog_calibrate_timer(struct analog_port
*port
)
376 struct gameport
*gameport
= port
->gameport
;
377 unsigned int i
, t
, tx
;
382 port
->speed
= 1000000;
384 local_irq_save(flags
);
387 analog_faketime
+= 830;
392 local_irq_restore(flags
);
394 port
->speed
= delta(t1
, t2
) - delta(t2
, t3
);
399 for (i
= 0; i
< 50; i
++) {
400 local_irq_save(flags
);
402 for (t
= 0; t
< 50; t
++) {
403 gameport_read(gameport
);
407 local_irq_restore(flags
);
409 t
= delta(t1
, t2
) - delta(t2
, t3
);
413 port
->loop
= tx
/ 50;
417 * analog_name() constructs a name for an analog joystick.
420 static void analog_name(struct analog
*analog
)
422 snprintf(analog
->name
, sizeof(analog
->name
), "Analog %d-axis %d-button",
423 hweight8(analog
->mask
& ANALOG_AXES_STD
),
424 hweight8(analog
->mask
& ANALOG_BTNS_STD
) + !!(analog
->mask
& ANALOG_BTNS_CHF
) * 2 +
425 hweight16(analog
->mask
& ANALOG_BTNS_GAMEPAD
) + !!(analog
->mask
& ANALOG_HBTN_CHF
) * 4);
427 if (analog
->mask
& ANALOG_HATS_ALL
)
428 snprintf(analog
->name
, sizeof(analog
->name
), "%s %d-hat",
429 analog
->name
, hweight16(analog
->mask
& ANALOG_HATS_ALL
));
431 if (analog
->mask
& ANALOG_HAT_FCS
)
432 strlcat(analog
->name
, " FCS", sizeof(analog
->name
));
433 if (analog
->mask
& ANALOG_ANY_CHF
)
434 strlcat(analog
->name
, (analog
->mask
& ANALOG_SAITEK
) ? " Saitek" : " CHF",
435 sizeof(analog
->name
));
437 strlcat(analog
->name
, (analog
->mask
& ANALOG_GAMEPAD
) ? " gamepad": " joystick",
438 sizeof(analog
->name
));
442 * analog_init_device()
445 static int analog_init_device(struct analog_port
*port
, struct analog
*analog
, int index
)
447 struct input_dev
*input_dev
;
448 int i
, j
, t
, v
, w
, x
, y
, z
;
452 snprintf(analog
->phys
, sizeof(analog
->phys
),
453 "%s/input%d", port
->gameport
->phys
, index
);
454 analog
->buttons
= (analog
->mask
& ANALOG_GAMEPAD
) ? analog_pad_btn
: analog_joy_btn
;
456 analog
->dev
= input_dev
= input_allocate_device();
460 input_dev
->name
= analog
->name
;
461 input_dev
->phys
= analog
->phys
;
462 input_dev
->id
.bustype
= BUS_GAMEPORT
;
463 input_dev
->id
.vendor
= GAMEPORT_ID_VENDOR_ANALOG
;
464 input_dev
->id
.product
= analog
->mask
>> 4;
465 input_dev
->id
.version
= 0x0100;
466 input_dev
->dev
.parent
= &port
->gameport
->dev
;
468 input_set_drvdata(input_dev
, port
);
470 input_dev
->open
= analog_open
;
471 input_dev
->close
= analog_close
;
473 input_dev
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_ABS
);
475 for (i
= j
= 0; i
< 4; i
++)
476 if (analog
->mask
& (1 << i
)) {
480 y
= (port
->axes
[0] + port
->axes
[1]) >> 1;
481 z
= y
- port
->axes
[i
];
486 if ((i
== 2 || i
== 3) && (j
== 2 || j
== 3) && (z
> (y
>> 3)))
489 if (analog
->mask
& ANALOG_SAITEK
) {
490 if (i
== 2) x
= port
->axes
[i
];
495 input_set_abs_params(input_dev
, t
, v
, (x
<< 1) - v
, port
->fuzz
, w
);
499 for (i
= j
= 0; i
< 3; i
++)
500 if (analog
->mask
& analog_exts
[i
])
501 for (x
= 0; x
< 2; x
++) {
502 t
= analog_hats
[j
++];
503 input_set_abs_params(input_dev
, t
, -1, 1, 0, 0);
506 for (i
= j
= 0; i
< 4; i
++)
507 if (analog
->mask
& (0x10 << i
))
508 set_bit(analog
->buttons
[j
++], input_dev
->keybit
);
510 if (analog
->mask
& ANALOG_BTNS_CHF
)
511 for (i
= 0; i
< 2; i
++)
512 set_bit(analog
->buttons
[j
++], input_dev
->keybit
);
514 if (analog
->mask
& ANALOG_HBTN_CHF
)
515 for (i
= 0; i
< 4; i
++)
516 set_bit(analog
->buttons
[j
++], input_dev
->keybit
);
518 for (i
= 0; i
< 4; i
++)
519 if (analog
->mask
& (ANALOG_BTN_TL
<< i
))
520 set_bit(analog_pads
[i
], input_dev
->keybit
);
522 analog_decode(analog
, port
->axes
, port
->initial
, port
->buttons
);
524 error
= input_register_device(analog
->dev
);
526 input_free_device(analog
->dev
);
534 * analog_init_devices() sets up device-specific values and registers the input devices.
537 static int analog_init_masks(struct analog_port
*port
)
540 struct analog
*analog
= port
->analog
;
546 if ((port
->mask
& 3) != 3 && port
->mask
!= 0xc) {
547 printk(KERN_WARNING
"analog.c: Unknown joystick device found "
548 "(data=%#x, %s), probably not analog joystick.\n",
549 port
->mask
, port
->gameport
->phys
);
554 i
= analog_options
[0]; /* FIXME !!! - need to specify options for different ports */
556 analog
[0].mask
= i
& 0xfffff;
558 analog
[0].mask
&= ~(ANALOG_AXES_STD
| ANALOG_HAT_FCS
| ANALOG_BTNS_GAMEPAD
)
559 | port
->mask
| ((port
->mask
<< 8) & ANALOG_HAT_FCS
)
560 | ((port
->mask
<< 10) & ANALOG_BTNS_TLR
) | ((port
->mask
<< 12) & ANALOG_BTNS_TLR2
);
562 analog
[0].mask
&= ~(ANALOG_HAT2_CHF
)
563 | ((analog
[0].mask
& ANALOG_HBTN_CHF
) ? 0 : ANALOG_HAT2_CHF
);
565 analog
[0].mask
&= ~(ANALOG_THROTTLE
| ANALOG_BTN_TR
| ANALOG_BTN_TR2
)
566 | ((~analog
[0].mask
& ANALOG_HAT_FCS
) >> 8)
567 | ((~analog
[0].mask
& ANALOG_HAT_FCS
) << 2)
568 | ((~analog
[0].mask
& ANALOG_HAT_FCS
) << 4);
570 analog
[0].mask
&= ~(ANALOG_THROTTLE
| ANALOG_RUDDER
)
571 | (((~analog
[0].mask
& ANALOG_BTNS_TLR
) >> 10)
572 & ((~analog
[0].mask
& ANALOG_BTNS_TLR2
) >> 12));
574 analog
[1].mask
= ((i
>> 20) & 0xff) | ((i
>> 12) & 0xf0000);
576 analog
[1].mask
&= (analog
[0].mask
& ANALOG_EXTENSIONS
) ? ANALOG_GAMEPAD
577 : (((ANALOG_BTNS_STD
| port
->mask
) & ~analog
[0].mask
) | ANALOG_GAMEPAD
);
581 for (i
= 0; i
< 4; i
++) max
[i
] = port
->axes
[i
] << 1;
583 if ((analog
[0].mask
& 0x7) == 0x7) max
[2] = (max
[0] + max
[1]) >> 1;
584 if ((analog
[0].mask
& 0xb) == 0xb) max
[3] = (max
[0] + max
[1]) >> 1;
585 if ((analog
[0].mask
& ANALOG_BTN_TL
) && !(analog
[0].mask
& ANALOG_BTN_TL2
)) max
[2] >>= 1;
586 if ((analog
[0].mask
& ANALOG_BTN_TR
) && !(analog
[0].mask
& ANALOG_BTN_TR2
)) max
[3] >>= 1;
587 if ((analog
[0].mask
& ANALOG_HAT_FCS
)) max
[3] >>= 1;
589 gameport_calibrate(port
->gameport
, port
->axes
, max
);
592 for (i
= 0; i
< 4; i
++)
593 port
->initial
[i
] = port
->axes
[i
];
595 return -!(analog
[0].mask
|| analog
[1].mask
);
598 static int analog_init_port(struct gameport
*gameport
, struct gameport_driver
*drv
, struct analog_port
*port
)
602 port
->gameport
= gameport
;
604 gameport_set_drvdata(gameport
, port
);
606 if (!gameport_open(gameport
, drv
, GAMEPORT_MODE_RAW
)) {
608 analog_calibrate_timer(port
);
610 gameport_trigger(gameport
);
611 t
= gameport_read(gameport
);
612 msleep(ANALOG_MAX_TIME
);
613 port
->mask
= (gameport_read(gameport
) ^ t
) & t
& 0xf;
614 port
->fuzz
= (port
->speed
* ANALOG_FUZZ_MAGIC
) / port
->loop
/ 1000 + ANALOG_FUZZ_BITS
;
616 for (i
= 0; i
< ANALOG_INIT_RETRIES
; i
++) {
617 if (!analog_cooked_read(port
))
619 msleep(ANALOG_MAX_TIME
);
624 msleep(ANALOG_MAX_TIME
);
625 t
= gameport_time(gameport
, ANALOG_MAX_TIME
* 1000);
626 gameport_trigger(gameport
);
627 while ((gameport_read(port
->gameport
) & port
->mask
) && (u
< t
))
629 udelay(ANALOG_SAITEK_DELAY
);
630 t
= gameport_time(gameport
, ANALOG_SAITEK_TIME
);
631 gameport_trigger(gameport
);
632 while ((gameport_read(port
->gameport
) & port
->mask
) && (v
< t
))
635 if (v
< (u
>> 1)) { /* FIXME - more than one port */
636 analog_options
[0] |= /* FIXME - more than one port */
637 ANALOG_SAITEK
| ANALOG_BTNS_CHF
| ANALOG_HBTN_CHF
| ANALOG_HAT1_CHF
;
641 gameport_close(gameport
);
644 if (!gameport_open(gameport
, drv
, GAMEPORT_MODE_COOKED
)) {
646 for (i
= 0; i
< ANALOG_INIT_RETRIES
; i
++)
647 if (!gameport_cooked_read(gameport
, port
->axes
, &port
->buttons
))
649 for (i
= 0; i
< 4; i
++)
650 if (port
->axes
[i
] != -1)
651 port
->mask
|= 1 << i
;
653 port
->fuzz
= gameport
->fuzz
;
658 return gameport_open(gameport
, drv
, GAMEPORT_MODE_RAW
);
661 static int analog_connect(struct gameport
*gameport
, struct gameport_driver
*drv
)
663 struct analog_port
*port
;
667 if (!(port
= kzalloc(sizeof(struct analog_port
), GFP_KERNEL
)))
670 err
= analog_init_port(gameport
, drv
, port
);
674 err
= analog_init_masks(port
);
678 gameport_set_poll_handler(gameport
, analog_poll
);
679 gameport_set_poll_interval(gameport
, 10);
681 for (i
= 0; i
< 2; i
++)
682 if (port
->analog
[i
].mask
) {
683 err
= analog_init_device(port
, port
->analog
+ i
, i
);
690 fail3
: while (--i
>= 0)
691 if (port
->analog
[i
].mask
)
692 input_unregister_device(port
->analog
[i
].dev
);
693 fail2
: gameport_close(gameport
);
694 fail1
: gameport_set_drvdata(gameport
, NULL
);
699 static void analog_disconnect(struct gameport
*gameport
)
701 struct analog_port
*port
= gameport_get_drvdata(gameport
);
704 for (i
= 0; i
< 2; i
++)
705 if (port
->analog
[i
].mask
)
706 input_unregister_device(port
->analog
[i
].dev
);
707 gameport_close(gameport
);
708 gameport_set_drvdata(gameport
, NULL
);
709 printk(KERN_INFO
"analog.c: %d out of %d reads (%d%%) on %s failed\n",
710 port
->bads
, port
->reads
, port
->reads
? (port
->bads
* 100 / port
->reads
) : 0,
711 port
->gameport
->phys
);
715 struct analog_types
{
720 static struct analog_types analog_types
[] = {
721 { "none", 0x00000000 },
722 { "auto", 0x000000ff },
723 { "2btn", 0x0000003f },
724 { "y-joy", 0x0cc00033 },
725 { "y-pad", 0x8cc80033 },
726 { "fcs", 0x000008f7 },
727 { "chf", 0x000002ff },
728 { "fullchf", 0x000007ff },
729 { "gamepad", 0x000830f3 },
730 { "gamepad8", 0x0008f0f3 },
734 static void analog_parse_options(void)
739 for (i
= 0; i
< js_nargs
; i
++) {
741 for (j
= 0; analog_types
[j
].name
; j
++)
742 if (!strcmp(analog_types
[j
].name
, js
[i
])) {
743 analog_options
[i
] = analog_types
[j
].value
;
746 if (analog_types
[j
].name
) continue;
748 analog_options
[i
] = simple_strtoul(js
[i
], &end
, 0);
749 if (end
!= js
[i
]) continue;
751 analog_options
[i
] = 0xff;
752 if (!strlen(js
[i
])) continue;
754 printk(KERN_WARNING
"analog.c: Bad config for port %d - \"%s\"\n", i
, js
[i
]);
757 for (; i
< ANALOG_PORTS
; i
++)
758 analog_options
[i
] = 0xff;
762 * The gameport device structure.
765 static struct gameport_driver analog_drv
= {
769 .description
= DRIVER_DESC
,
770 .connect
= analog_connect
,
771 .disconnect
= analog_disconnect
,
774 static int __init
analog_init(void)
776 analog_parse_options();
777 return gameport_register_driver(&analog_drv
);
780 static void __exit
analog_exit(void)
782 gameport_unregister_driver(&analog_drv
);
785 module_init(analog_init
);
786 module_exit(analog_exit
);