dt-bindings: mtd: ingenic: Use standard ecc-engine property
[linux/fpc-iii.git] / drivers / input / joystick / joydump.c
blob344ab44ff5817405b85df47b24a6e364d27816af
1 /*
2 * Copyright (c) 1996-2001 Vojtech Pavlik
3 */
5 /*
6 * This is just a very simple driver that can dump the data
7 * out of the joystick port into the syslog ...
8 */
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"
34 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
35 MODULE_DESCRIPTION(DRIVER_DESC);
36 MODULE_LICENSE("GPL");
38 #define BUF_SIZE 256
40 struct joydump {
41 unsigned int time;
42 unsigned char data;
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 */
49 int axes[4], buttons;
50 int i, j, t, timeout;
51 unsigned long flags;
52 unsigned char u;
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");
66 return -ENODEV;
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);
80 if (!buf) {
81 printk(KERN_INFO "joydump: no memory for testing\n");
82 goto jd_end;
84 dump = buf;
85 t = 0;
86 i = 1;
88 local_irq_save(flags);
90 u = gameport_read(gameport);
92 dump->data = u;
93 dump->time = t;
94 dump++;
96 gameport_trigger(gameport);
98 while (i < BUF_SIZE && t < timeout) {
100 dump->data = gameport_read(gameport);
102 if (dump->data ^ u) {
103 u = dump->data;
104 dump->time = t;
105 i++;
106 dump++;
108 t++;
111 local_irq_restore(flags);
114 * Dump data.
117 t = i;
118 dump = buf;
119 prev = dump;
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);
125 printk(" |\n");
126 dump++;
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);
133 printk(" |\n");
135 kfree(buf);
137 jd_end:
138 printk(KERN_INFO "joydump: `------------------- END -----------------'\n");
140 return 0;
143 static void joydump_disconnect(struct gameport *gameport)
145 gameport_close(gameport);
148 static struct gameport_driver joydump_drv = {
149 .driver = {
150 .name = "joydump",
152 .description = DRIVER_DESC,
153 .connect = joydump_connect,
154 .disconnect = joydump_disconnect,
157 module_gameport_driver(joydump_drv);