2 * Copyright (c) 1996-2001 Vojtech Pavlik
6 * This is just a very simple driver that can dump the data
7 * out of the joystick port into the syslog ...
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * Should you need to contact me, the author, you can do so either by
26 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
27 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
30 #include <linux/module.h>
31 #include <linux/gameport.h>
32 #include <linux/kernel.h>
33 #include <linux/delay.h>
34 #include <linux/init.h>
35 #include <linux/slab.h>
37 #define DRIVER_DESC "Gameport data dumper module"
39 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
40 MODULE_DESCRIPTION(DRIVER_DESC);
41 MODULE_LICENSE("GPL");
50 static int joydump_connect(struct gameport *gameport, struct gameport_driver *drv)
52 struct joydump *buf; /* all entries */
53 struct joydump *dump, *prev; /* one entry each */
59 printk(KERN_INFO "joydump: ,------------------ START ----------------.\n");
60 printk(KERN_INFO "joydump: | Dumping: %30s |\n", gameport->phys);
61 printk(KERN_INFO "joydump: | Speed: %28d kHz |\n", gameport->speed);
63 if (gameport_open(gameport, drv, GAMEPORT_MODE_RAW)) {
65 printk(KERN_INFO "joydump: | Raw mode not available - trying cooked. |\n");
67 if (gameport_open(gameport, drv, GAMEPORT_MODE_COOKED)) {
69 printk(KERN_INFO "joydump: | Cooked not available either. Failing. |\n");
70 printk(KERN_INFO "joydump: `------------------- END -----------------'\n");
74 gameport_cooked_read(gameport, axes, &buttons);
76 for (i = 0; i < 4; i++)
77 printk(KERN_INFO "joydump: | Axis %d: %4d. |\n", i, axes[i]);
78 printk(KERN_INFO "joydump: | Buttons %02x. |\n", buttons);
79 printk(KERN_INFO "joydump: `------------------- END -----------------'\n");
82 timeout = gameport_time(gameport, 10000); /* 10 ms */
84 buf = kmalloc(BUF_SIZE * sizeof(struct joydump), GFP_KERNEL);
86 printk(KERN_INFO "joydump: no memory for testing\n");
93 local_irq_save(flags);
95 u = gameport_read(gameport);
101 gameport_trigger(gameport);
103 while (i < BUF_SIZE && t < timeout) {
105 dump->data = gameport_read(gameport);
107 if (dump->data ^ u) {
116 local_irq_restore(flags);
126 printk(KERN_INFO "joydump: >------------------ DATA -----------------<\n");
127 printk(KERN_INFO "joydump: | index: %3d delta: %3d us data: ", 0, 0);
128 for (j = 7; j >= 0; j--)
129 printk("%d", (dump->data >> j) & 1);
133 for (i = 1; i < t; i++, dump++, prev++) {
134 printk(KERN_INFO "joydump: | index: %3d delta: %3d us data: ",
135 i, dump->time - prev->time);
136 for (j = 7; j >= 0; j--)
137 printk("%d", (dump->data >> j) & 1);
143 printk(KERN_INFO "joydump: `------------------- END -----------------'\n");
148 static void joydump_disconnect(struct gameport *gameport)
150 gameport_close(gameport);
153 static struct gameport_driver joydump_drv = {
157 .description = DRIVER_DESC,
158 .connect = joydump_connect,
159 .disconnect = joydump_disconnect,
162 static int __init joydump_init(void)
164 gameport_register_driver(&joydump_drv);
168 static void __exit joydump_exit(void)
170 gameport_unregister_driver(&joydump_drv);
173 module_init(joydump_init);
174 module_exit(joydump_exit);