2 * $Id: joydump.c,v 1.1 2002/01/23 06:56:16 jsimmons Exp $
4 * Copyright (c) 1996-2001 Vojtech Pavlik
8 * This is just a very simple driver that can dump the data
9 * out of the joystick port into the syslog ...
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.
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.
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
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
32 #include <linux/module.h>
33 #include <linux/gameport.h>
34 #include <linux/kernel.h>
35 #include <linux/delay.h>
36 #include <linux/init.h>
38 #define DRIVER_DESC "Gameport data dumper module"
40 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
41 MODULE_DESCRIPTION(DRIVER_DESC
);
42 MODULE_LICENSE("GPL");
51 static int joydump_connect(struct gameport
*gameport
, struct gameport_driver
*drv
)
53 struct joydump
*buf
; /* all entries */
54 struct joydump
*dump
, *prev
; /* one entry each */
60 printk(KERN_INFO
"joydump: ,------------------ START ----------------.\n");
61 printk(KERN_INFO
"joydump: | Dumping: %30s |\n", gameport
->phys
);
62 printk(KERN_INFO
"joydump: | Speed: %28d kHz |\n", gameport
->speed
);
64 if (gameport_open(gameport
, drv
, GAMEPORT_MODE_RAW
)) {
66 printk(KERN_INFO
"joydump: | Raw mode not available - trying cooked. |\n");
68 if (gameport_open(gameport
, drv
, GAMEPORT_MODE_COOKED
)) {
70 printk(KERN_INFO
"joydump: | Cooked not available either. Failing. |\n");
71 printk(KERN_INFO
"joydump: `------------------- END -----------------'\n");
75 gameport_cooked_read(gameport
, axes
, &buttons
);
77 for (i
= 0; i
< 4; i
++)
78 printk(KERN_INFO
"joydump: | Axis %d: %4d. |\n", i
, axes
[i
]);
79 printk(KERN_INFO
"joydump: | Buttons %02x. |\n", buttons
);
80 printk(KERN_INFO
"joydump: `------------------- END -----------------'\n");
83 timeout
= gameport_time(gameport
, 10000); /* 10 ms */
85 buf
= kmalloc(BUF_SIZE
* sizeof(struct joydump
), GFP_KERNEL
);
87 printk(KERN_INFO
"joydump: no memory for testing\n");
94 local_irq_save(flags
);
96 u
= gameport_read(gameport
);
102 gameport_trigger(gameport
);
104 while (i
< BUF_SIZE
&& t
< timeout
) {
106 dump
->data
= gameport_read(gameport
);
108 if (dump
->data
^ u
) {
117 local_irq_restore(flags
);
127 printk(KERN_INFO
"joydump: >------------------ DATA -----------------<\n");
128 printk(KERN_INFO
"joydump: | index: %3d delta: %3d us data: ", 0, 0);
129 for (j
= 7; j
>= 0; j
--)
130 printk("%d", (dump
->data
>> j
) & 1);
134 for (i
= 1; i
< t
; i
++, dump
++, prev
++) {
135 printk(KERN_INFO
"joydump: | index: %3d delta: %3d us data: ",
136 i
, dump
->time
- prev
->time
);
137 for (j
= 7; j
>= 0; j
--)
138 printk("%d", (dump
->data
>> j
) & 1);
144 printk(KERN_INFO
"joydump: `------------------- END -----------------'\n");
149 static void joydump_disconnect(struct gameport
*gameport
)
151 gameport_close(gameport
);
154 static struct gameport_driver joydump_drv
= {
158 .description
= DRIVER_DESC
,
159 .connect
= joydump_connect
,
160 .disconnect
= joydump_disconnect
,
163 static int __init
joydump_init(void)
165 gameport_register_driver(&joydump_drv
);
169 static void __exit
joydump_exit(void)
171 gameport_unregister_driver(&joydump_drv
);
174 module_init(joydump_init
);
175 module_exit(joydump_exit
);