Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / input / joystick / joydump.c
blob865652a7821da3b2fb49a664fceb9b209d3b7911
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) 1996-2001 Vojtech Pavlik
4 */
6 /*
7 * This is just a very simple driver that can dump the data
8 * out of the joystick port into the syslog ...
9 */
11 #include <linux/module.h>
12 #include <linux/gameport.h>
13 #include <linux/kernel.h>
14 #include <linux/delay.h>
15 #include <linux/slab.h>
17 #define DRIVER_DESC "Gameport data dumper module"
19 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
20 MODULE_DESCRIPTION(DRIVER_DESC);
21 MODULE_LICENSE("GPL");
23 #define BUF_SIZE 256
25 struct joydump {
26 unsigned int time;
27 unsigned char data;
30 static int joydump_connect(struct gameport *gameport, struct gameport_driver *drv)
32 struct joydump *buf; /* all entries */
33 struct joydump *dump, *prev; /* one entry each */
34 int axes[4], buttons;
35 int i, j, t, timeout;
36 unsigned long flags;
37 unsigned char u;
39 printk(KERN_INFO "joydump: ,------------------ START ----------------.\n");
40 printk(KERN_INFO "joydump: | Dumping: %30s |\n", gameport->phys);
41 printk(KERN_INFO "joydump: | Speed: %28d kHz |\n", gameport->speed);
43 if (gameport_open(gameport, drv, GAMEPORT_MODE_RAW)) {
45 printk(KERN_INFO "joydump: | Raw mode not available - trying cooked. |\n");
47 if (gameport_open(gameport, drv, GAMEPORT_MODE_COOKED)) {
49 printk(KERN_INFO "joydump: | Cooked not available either. Failing. |\n");
50 printk(KERN_INFO "joydump: `------------------- END -----------------'\n");
51 return -ENODEV;
54 gameport_cooked_read(gameport, axes, &buttons);
56 for (i = 0; i < 4; i++)
57 printk(KERN_INFO "joydump: | Axis %d: %4d. |\n", i, axes[i]);
58 printk(KERN_INFO "joydump: | Buttons %02x. |\n", buttons);
59 printk(KERN_INFO "joydump: `------------------- END -----------------'\n");
62 timeout = gameport_time(gameport, 10000); /* 10 ms */
64 buf = kmalloc_array(BUF_SIZE, sizeof(struct joydump), GFP_KERNEL);
65 if (!buf) {
66 printk(KERN_INFO "joydump: no memory for testing\n");
67 goto jd_end;
69 dump = buf;
70 t = 0;
71 i = 1;
73 local_irq_save(flags);
75 u = gameport_read(gameport);
77 dump->data = u;
78 dump->time = t;
79 dump++;
81 gameport_trigger(gameport);
83 while (i < BUF_SIZE && t < timeout) {
85 dump->data = gameport_read(gameport);
87 if (dump->data ^ u) {
88 u = dump->data;
89 dump->time = t;
90 i++;
91 dump++;
93 t++;
96 local_irq_restore(flags);
99 * Dump data.
102 t = i;
103 dump = buf;
104 prev = dump;
106 printk(KERN_INFO "joydump: >------------------ DATA -----------------<\n");
107 printk(KERN_INFO "joydump: | index: %3d delta: %3d us data: ", 0, 0);
108 for (j = 7; j >= 0; j--)
109 printk("%d", (dump->data >> j) & 1);
110 printk(" |\n");
111 dump++;
113 for (i = 1; i < t; i++, dump++, prev++) {
114 printk(KERN_INFO "joydump: | index: %3d delta: %3d us data: ",
115 i, dump->time - prev->time);
116 for (j = 7; j >= 0; j--)
117 printk("%d", (dump->data >> j) & 1);
118 printk(" |\n");
120 kfree(buf);
122 jd_end:
123 printk(KERN_INFO "joydump: `------------------- END -----------------'\n");
125 return 0;
128 static void joydump_disconnect(struct gameport *gameport)
130 gameport_close(gameport);
133 static struct gameport_driver joydump_drv = {
134 .driver = {
135 .name = "joydump",
137 .description = DRIVER_DESC,
138 .connect = joydump_connect,
139 .disconnect = joydump_disconnect,
142 module_gameport_driver(joydump_drv);