31 #include <linux/errno.h>
33 #include <linux/kernel.h>
34 #include <linux/module.h>
36 #include <linux/gameport.h>
39 #define L4_SELECT_ANALOG 0xa4
40 #define L4_SELECT_DIGITAL 0xa5
41 #define L4_SELECT_SECONDARY 0xa6
42 #define L4_CMD_ID 0x80
43 #define L4_CMD_GETCAL 0x92
44 #define L4_CMD_SETCAL 0x93
58 static struct l4 l4_ports[8];
64 static int l4_wait_ready(
void)
88 if (l4_wait_ready())
goto fail;
91 for (i = 0; i < 4; i++)
92 if (status & (1 << i)) {
93 if (l4_wait_ready())
goto fail;
95 if (axes[i] > 252) axes[
i] = -1;
99 if (l4_wait_ready())
goto fail;
109 static int l4_open(
struct gameport *gameport,
int mode)
123 static int l4_getcal(
int port,
int *cal)
143 for (i = 0; i < 4; i++) {
159 static int l4_setcal(
int port,
int *cal)
179 for (i = 0; i < 4; i++) {
196 static int l4_calibrate(
struct gameport *gameport,
int *axes,
int *
max)
202 if (l4_getcal(l4->
port, cal))
205 for (i = 0; i < 4; i++) {
206 t = (max[
i] * cal[
i]) / 200;
207 t = (t < 1) ? 1 : ((t > 255) ? 255 : t);
208 axes[
i] = (axes[
i] < 0) ? -1 : (axes[i] * cal[i]) /
t;
209 axes[
i] = (axes[
i] > 252) ? 252 : axes[i];
213 if (l4_setcal(l4->
port, cal))
219 static int __init l4_create_ports(
int card_no)
222 struct gameport *
port;
225 for (i = 0; i < 4; i++) {
227 idx = card_no * 4 +
i;
230 if (!(l4->
gameport = port = gameport_allocate_port())) {
241 port->
open = l4_open;
245 gameport_set_name(port,
"PDPI Lightning 4");
255 static int __init l4_add_card(
int card_no)
257 int cal[4] = { 255, 255, 255, 255 };
286 result = l4_create_ports(card_no);
291 card_no ?
"secondary" :
"primary", rev >> 4, rev,
L4_PORT);
293 for (i = 0; i < 4; i++) {
294 l4 = &l4_ports[card_no * 4 +
i];
297 l4_setcal(l4->
port, cal);
298 gameport_register_port(l4->
gameport);
304 static int __init l4_init(
void)
311 for (i = 0; i < 2; i++)
312 if (l4_add_card(i) == 0)
325 static void __exit l4_exit(
void)
328 int cal[4] = { 59, 59, 59, 59 };
330 for (i = 0; i < 8; i++)
331 if (l4_ports[i].gameport) {
332 l4_setcal(l4_ports[i].port, cal);