initial commit with v2.6.9
[linux-2.6.9-moxart.git] / drivers / input / joystick / joydump.c
blob15962a684dd7f439281cdf355527ed0819521842
1 /*
2 * $Id: joydump.c,v 1.1 2002/01/23 06:56:16 jsimmons Exp $
4 * Copyright (c) 1996-2001 Vojtech Pavlik
5 */
7 /*
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 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
39 MODULE_DESCRIPTION("Gameport data dumper module");
40 MODULE_LICENSE("GPL");
42 #define BUF_SIZE 256
44 struct joydump {
45 unsigned int time;
46 unsigned char data;
49 static void __devinit joydump_connect(struct gameport *gameport, struct gameport_dev *dev)
51 struct joydump buf[BUF_SIZE];
52 int axes[4], buttons;
53 int i, j, t, timeout;
54 unsigned long flags;
55 unsigned char u;
57 printk(KERN_INFO "joydump: ,------------------- START ------------------.\n");
58 printk(KERN_INFO "joydump: | Dumping gameport%s.\n", gameport->phys);
59 printk(KERN_INFO "joydump: | Speed: %4d kHz. |\n", gameport->speed);
61 if (gameport_open(gameport, dev, GAMEPORT_MODE_RAW)) {
63 printk(KERN_INFO "joydump: | Raw mode not available - trying cooked. |\n");
65 if (gameport_open(gameport, dev, GAMEPORT_MODE_COOKED)) {
67 printk(KERN_INFO "joydump: | Cooked not available either. Failing. |\n");
68 printk(KERN_INFO "joydump: `-------------------- END -------------------'\n");
69 return;
72 gameport_cooked_read(gameport, axes, &buttons);
74 for (i = 0; i < 4; i++)
75 printk(KERN_INFO "joydump: | Axis %d: %4d. |\n", i, axes[i]);
76 printk(KERN_INFO "joydump: | Buttons %02x. |\n", buttons);
77 printk(KERN_INFO "joydump: `-------------------- END -------------------'\n");
80 timeout = gameport_time(gameport, 10000); /* 10 ms */
81 t = 0;
82 i = 1;
84 local_irq_save(flags);
86 u = gameport_read(gameport);
88 buf[0].data = u;
89 buf[0].time = t;
91 gameport_trigger(gameport);
93 while (i < BUF_SIZE && t < timeout) {
95 buf[i].data = gameport_read(gameport);
97 if (buf[i].data ^ u) {
98 u = buf[i].data;
99 buf[i].time = t;
100 i++;
102 t++;
105 local_irq_restore(flags);
108 * Dump data.
111 t = i;
113 printk(KERN_INFO "joydump: >------------------- DATA -------------------<\n");
114 printk(KERN_INFO "joydump: | index: %3d delta: %3d.%02d us data: ", 0, 0, 0);
115 for (j = 7; j >= 0; j--)
116 printk("%d",(buf[0].data >> j) & 1);
117 printk(" |\n");
118 for (i = 1; i < t; i++) {
119 printk(KERN_INFO "joydump: | index: %3d delta: %3d us data: ",
120 i, buf[i].time - buf[i-1].time);
121 for (j = 7; j >= 0; j--)
122 printk("%d",(buf[i].data >> j) & 1);
123 printk(" |\n");
126 printk(KERN_INFO "joydump: `-------------------- END -------------------'\n");
129 static void __devexit joydump_disconnect(struct gameport *gameport)
131 gameport_close(gameport);
134 static struct gameport_dev joydump_dev = {
135 .connect = joydump_connect,
136 .disconnect = joydump_disconnect,
139 static int __init joydump_init(void)
141 gameport_register_device(&joydump_dev);
142 return 0;
145 static void __exit joydump_exit(void)
147 gameport_unregister_device(&joydump_dev);
150 module_init(joydump_init);
151 module_exit(joydump_exit);