Linux Audio

Check our new training course

Loading...
v5.9
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
  3 *  Copyright (c) 1996-2001 Vojtech Pavlik
  4 */
  5
  6/*
  7 * This is just a very simple driver that can dump the data
  8 * out of the joystick port into the syslog ...
  9 */
 10
 11/*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 12 */
 13
 14#include <linux/module.h>
 15#include <linux/gameport.h>
 16#include <linux/kernel.h>
 17#include <linux/delay.h>
 
 18#include <linux/slab.h>
 19
 20#define DRIVER_DESC	"Gameport data dumper module"
 21
 22MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
 23MODULE_DESCRIPTION(DRIVER_DESC);
 24MODULE_LICENSE("GPL");
 25
 26#define BUF_SIZE 256
 27
 28struct joydump {
 29	unsigned int time;
 30	unsigned char data;
 31};
 32
 33static int joydump_connect(struct gameport *gameport, struct gameport_driver *drv)
 34{
 35	struct joydump *buf;	/* all entries */
 36	struct joydump *dump, *prev;	/* one entry each */
 37	int axes[4], buttons;
 38	int i, j, t, timeout;
 39	unsigned long flags;
 40	unsigned char u;
 41
 42	printk(KERN_INFO "joydump: ,------------------ START ----------------.\n");
 43	printk(KERN_INFO "joydump: | Dumping: %30s |\n", gameport->phys);
 44	printk(KERN_INFO "joydump: | Speed: %28d kHz |\n", gameport->speed);
 45
 46	if (gameport_open(gameport, drv, GAMEPORT_MODE_RAW)) {
 47
 48		printk(KERN_INFO "joydump: | Raw mode not available - trying cooked.    |\n");
 49
 50		if (gameport_open(gameport, drv, GAMEPORT_MODE_COOKED)) {
 51
 52			printk(KERN_INFO "joydump: | Cooked not available either. Failing.   |\n");
 53			printk(KERN_INFO "joydump: `------------------- END -----------------'\n");
 54			return -ENODEV;
 55		}
 56
 57		gameport_cooked_read(gameport, axes, &buttons);
 58
 59		for (i = 0; i < 4; i++)
 60			printk(KERN_INFO "joydump: | Axis %d: %4d.                           |\n", i, axes[i]);
 61		printk(KERN_INFO "joydump: | Buttons %02x.                             |\n", buttons);
 62		printk(KERN_INFO "joydump: `------------------- END -----------------'\n");
 63	}
 64
 65	timeout = gameport_time(gameport, 10000); /* 10 ms */
 66
 67	buf = kmalloc_array(BUF_SIZE, sizeof(struct joydump), GFP_KERNEL);
 68	if (!buf) {
 69		printk(KERN_INFO "joydump: no memory for testing\n");
 70		goto jd_end;
 71	}
 72	dump = buf;
 73	t = 0;
 74	i = 1;
 75
 76	local_irq_save(flags);
 77
 78	u = gameport_read(gameport);
 79
 80	dump->data = u;
 81	dump->time = t;
 82	dump++;
 83
 84	gameport_trigger(gameport);
 85
 86	while (i < BUF_SIZE && t < timeout) {
 87
 88		dump->data = gameport_read(gameport);
 89
 90		if (dump->data ^ u) {
 91			u = dump->data;
 92			dump->time = t;
 93			i++;
 94			dump++;
 95		}
 96		t++;
 97	}
 98
 99	local_irq_restore(flags);
100
101/*
102 * Dump data.
103 */
104
105	t = i;
106	dump = buf;
107	prev = dump;
108
109	printk(KERN_INFO "joydump: >------------------ DATA -----------------<\n");
110	printk(KERN_INFO "joydump: | index: %3d delta: %3d us data: ", 0, 0);
111	for (j = 7; j >= 0; j--)
112		printk("%d", (dump->data >> j) & 1);
113	printk(" |\n");
114	dump++;
115
116	for (i = 1; i < t; i++, dump++, prev++) {
117		printk(KERN_INFO "joydump: | index: %3d delta: %3d us data: ",
118			i, dump->time - prev->time);
119		for (j = 7; j >= 0; j--)
120			printk("%d", (dump->data >> j) & 1);
121		printk(" |\n");
122	}
123	kfree(buf);
124
125jd_end:
126	printk(KERN_INFO "joydump: `------------------- END -----------------'\n");
127
128	return 0;
129}
130
131static void joydump_disconnect(struct gameport *gameport)
132{
133	gameport_close(gameport);
134}
135
136static struct gameport_driver joydump_drv = {
137	.driver		= {
138		.name	= "joydump",
139	},
140	.description	= DRIVER_DESC,
141	.connect	= joydump_connect,
142	.disconnect	= joydump_disconnect,
143};
144
145module_gameport_driver(joydump_drv);
v3.5.6
 
  1/*
  2 *  Copyright (c) 1996-2001 Vojtech Pavlik
  3 */
  4
  5/*
  6 * This is just a very simple driver that can dump the data
  7 * out of the joystick port into the syslog ...
  8 */
  9
 10/*
 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.
 15 *
 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.
 20 *
 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
 24 *
 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
 28 */
 29
 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>
 36
 37#define DRIVER_DESC	"Gameport data dumper module"
 38
 39MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
 40MODULE_DESCRIPTION(DRIVER_DESC);
 41MODULE_LICENSE("GPL");
 42
 43#define BUF_SIZE 256
 44
 45struct joydump {
 46	unsigned int time;
 47	unsigned char data;
 48};
 49
 50static int joydump_connect(struct gameport *gameport, struct gameport_driver *drv)
 51{
 52	struct joydump *buf;	/* all entries */
 53	struct joydump *dump, *prev;	/* one entry each */
 54	int axes[4], buttons;
 55	int i, j, t, timeout;
 56	unsigned long flags;
 57	unsigned char u;
 58
 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);
 62
 63	if (gameport_open(gameport, drv, GAMEPORT_MODE_RAW)) {
 64
 65		printk(KERN_INFO "joydump: | Raw mode not available - trying cooked.    |\n");
 66
 67		if (gameport_open(gameport, drv, GAMEPORT_MODE_COOKED)) {
 68
 69			printk(KERN_INFO "joydump: | Cooked not available either. Failing.   |\n");
 70			printk(KERN_INFO "joydump: `------------------- END -----------------'\n");
 71			return -ENODEV;
 72		}
 73
 74		gameport_cooked_read(gameport, axes, &buttons);
 75
 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");
 80	}
 81
 82	timeout = gameport_time(gameport, 10000); /* 10 ms */
 83
 84	buf = kmalloc(BUF_SIZE * sizeof(struct joydump), GFP_KERNEL);
 85	if (!buf) {
 86		printk(KERN_INFO "joydump: no memory for testing\n");
 87		goto jd_end;
 88	}
 89	dump = buf;
 90	t = 0;
 91	i = 1;
 92
 93	local_irq_save(flags);
 94
 95	u = gameport_read(gameport);
 96
 97	dump->data = u;
 98	dump->time = t;
 99	dump++;
100
101	gameport_trigger(gameport);
102
103	while (i < BUF_SIZE && t < timeout) {
104
105		dump->data = gameport_read(gameport);
106
107		if (dump->data ^ u) {
108			u = dump->data;
109			dump->time = t;
110			i++;
111			dump++;
112		}
113		t++;
114	}
115
116	local_irq_restore(flags);
117
118/*
119 * Dump data.
120 */
121
122	t = i;
123	dump = buf;
124	prev = dump;
125
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);
130	printk(" |\n");
131	dump++;
132
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);
138		printk(" |\n");
139	}
140	kfree(buf);
141
142jd_end:
143	printk(KERN_INFO "joydump: `------------------- END -----------------'\n");
144
145	return 0;
146}
147
148static void joydump_disconnect(struct gameport *gameport)
149{
150	gameport_close(gameport);
151}
152
153static struct gameport_driver joydump_drv = {
154	.driver		= {
155		.name	= "joydump",
156	},
157	.description	= DRIVER_DESC,
158	.connect	= joydump_connect,
159	.disconnect	= joydump_disconnect,
160};
161
162module_gameport_driver(joydump_drv);