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
26 #include <linux/module.h>
27 #include <linux/gameport.h>
28 #include <linux/kernel.h>
29 #include <linux/delay.h>
30 #include <linux/slab.h>
32 #define DRIVER_DESC "Gameport data dumper module"
35 MODULE_DESCRIPTION(DRIVER_DESC);
36 MODULE_LICENSE("GPL");
45 static int joydump_connect(struct gameport *gameport, struct gameport_driver *drv)
47 struct joydump *buf; /* all entries */
48 struct joydump *dump, *prev; /* one entry each */
54 printk(KERN_INFO "joydump: ,------------------ START ----------------.\n");
55 printk(KERN_INFO "joydump: | Dumping: %30s |\n", gameport->phys);
56 printk(KERN_INFO "joydump: | Speed: %28d kHz |\n", gameport->speed);
58 if (gameport_open(gameport, drv, GAMEPORT_MODE_RAW)) {
60 printk(KERN_INFO "joydump: | Raw mode not available - trying cooked. |\n");
62 if (gameport_open(gameport, drv, GAMEPORT_MODE_COOKED)) {
64 printk(KERN_INFO "joydump: | Cooked not available either. Failing. |\n");
65 printk(KERN_INFO "joydump: `------------------- END -----------------'\n");
69 gameport_cooked_read(gameport, axes, &buttons);
71 for (i = 0; i < 4; i++)
72 printk(KERN_INFO "joydump: | Axis %d: %4d. |\n", i, axes[i]);
73 printk(KERN_INFO "joydump: | Buttons %02x. |\n", buttons);
74 printk(KERN_INFO "joydump: `------------------- END -----------------'\n");
77 timeout = gameport_time(gameport, 10000); /* 10 ms */
79 buf = kmalloc_array(BUF_SIZE, sizeof(struct joydump), GFP_KERNEL);
81 printk(KERN_INFO "joydump: no memory for testing\n");
88 local_irq_save(flags);
90 u = gameport_read(gameport);
96 gameport_trigger(gameport);
98 while (i < BUF_SIZE && t < timeout) {
100 dump->data = gameport_read(gameport);
102 if (dump->data ^ u) {
111 local_irq_restore(flags);
121 printk(KERN_INFO "joydump: >------------------ DATA -----------------<\n");
122 printk(KERN_INFO "joydump: | index: %3d delta: %3d us data: ", 0, 0);
123 for (j = 7; j >= 0; j--)
124 printk("%d", (dump->data >> j) & 1);
128 for (i = 1; i < t; i++, dump++, prev++) {
129 printk(KERN_INFO "joydump: | index: %3d delta: %3d us data: ",
130 i, dump->time - prev->time);
131 for (j = 7; j >= 0; j--)
132 printk("%d", (dump->data >> j) & 1);
138 printk(KERN_INFO "joydump: `------------------- END -----------------'\n");
143 static void joydump_disconnect(struct gameport *gameport)
145 gameport_close(gameport);
148 static struct gameport_driver joydump_drv = {
152 .description = DRIVER_DESC,
153 .connect = joydump_connect,
154 .disconnect = joydump_disconnect,
157 module_gameport_driver(joydump_drv);