Linux Audio

Check our new training course

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