Path: blob/master/drivers/input/joystick/joydump.c
15109 views
/*1* Copyright (c) 1996-2001 Vojtech Pavlik2*/34/*5* This is just a very simple driver that can dump the data6* out of the joystick port into the syslog ...7*/89/*10* This program is free software; you can redistribute it and/or modify11* it under the terms of the GNU General Public License as published by12* the Free Software Foundation; either version 2 of the License, or13* (at your option) any later version.14*15* This program is distributed in the hope that it will be useful,16* but WITHOUT ANY WARRANTY; without even the implied warranty of17* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the18* GNU General Public License for more details.19*20* You should have received a copy of the GNU General Public License21* along with this program; if not, write to the Free Software22* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA23*24* Should you need to contact me, the author, you can do so either by25* e-mail - mail your message to <[email protected]>, or by paper mail:26* Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic27*/2829#include <linux/module.h>30#include <linux/gameport.h>31#include <linux/kernel.h>32#include <linux/delay.h>33#include <linux/init.h>34#include <linux/slab.h>3536#define DRIVER_DESC "Gameport data dumper module"3738MODULE_AUTHOR("Vojtech Pavlik <[email protected]>");39MODULE_DESCRIPTION(DRIVER_DESC);40MODULE_LICENSE("GPL");4142#define BUF_SIZE 2564344struct joydump {45unsigned int time;46unsigned char data;47};4849static int joydump_connect(struct gameport *gameport, struct gameport_driver *drv)50{51struct joydump *buf; /* all entries */52struct joydump *dump, *prev; /* one entry each */53int axes[4], buttons;54int i, j, t, timeout;55unsigned long flags;56unsigned char u;5758printk(KERN_INFO "joydump: ,------------------ START ----------------.\n");59printk(KERN_INFO "joydump: | Dumping: %30s |\n", gameport->phys);60printk(KERN_INFO "joydump: | Speed: %28d kHz |\n", gameport->speed);6162if (gameport_open(gameport, drv, GAMEPORT_MODE_RAW)) {6364printk(KERN_INFO "joydump: | Raw mode not available - trying cooked. |\n");6566if (gameport_open(gameport, drv, GAMEPORT_MODE_COOKED)) {6768printk(KERN_INFO "joydump: | Cooked not available either. Failing. |\n");69printk(KERN_INFO "joydump: `------------------- END -----------------'\n");70return -ENODEV;71}7273gameport_cooked_read(gameport, axes, &buttons);7475for (i = 0; i < 4; i++)76printk(KERN_INFO "joydump: | Axis %d: %4d. |\n", i, axes[i]);77printk(KERN_INFO "joydump: | Buttons %02x. |\n", buttons);78printk(KERN_INFO "joydump: `------------------- END -----------------'\n");79}8081timeout = gameport_time(gameport, 10000); /* 10 ms */8283buf = kmalloc(BUF_SIZE * sizeof(struct joydump), GFP_KERNEL);84if (!buf) {85printk(KERN_INFO "joydump: no memory for testing\n");86goto jd_end;87}88dump = buf;89t = 0;90i = 1;9192local_irq_save(flags);9394u = gameport_read(gameport);9596dump->data = u;97dump->time = t;98dump++;99100gameport_trigger(gameport);101102while (i < BUF_SIZE && t < timeout) {103104dump->data = gameport_read(gameport);105106if (dump->data ^ u) {107u = dump->data;108dump->time = t;109i++;110dump++;111}112t++;113}114115local_irq_restore(flags);116117/*118* Dump data.119*/120121t = i;122dump = buf;123prev = dump;124125printk(KERN_INFO "joydump: >------------------ DATA -----------------<\n");126printk(KERN_INFO "joydump: | index: %3d delta: %3d us data: ", 0, 0);127for (j = 7; j >= 0; j--)128printk("%d", (dump->data >> j) & 1);129printk(" |\n");130dump++;131132for (i = 1; i < t; i++, dump++, prev++) {133printk(KERN_INFO "joydump: | index: %3d delta: %3d us data: ",134i, dump->time - prev->time);135for (j = 7; j >= 0; j--)136printk("%d", (dump->data >> j) & 1);137printk(" |\n");138}139kfree(buf);140141jd_end:142printk(KERN_INFO "joydump: `------------------- END -----------------'\n");143144return 0;145}146147static void joydump_disconnect(struct gameport *gameport)148{149gameport_close(gameport);150}151152static struct gameport_driver joydump_drv = {153.driver = {154.name = "joydump",155},156.description = DRIVER_DESC,157.connect = joydump_connect,158.disconnect = joydump_disconnect,159};160161static int __init joydump_init(void)162{163return gameport_register_driver(&joydump_drv);164}165166static void __exit joydump_exit(void)167{168gameport_unregister_driver(&joydump_drv);169}170171module_init(joydump_init);172module_exit(joydump_exit);173174175