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 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> 31 32 #define DRIVER_DESC "Gameport data dumper module" 33 34 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); 35 MODULE_DESCRIPTION(DRIVER_DESC); 36 MODULE_LICENSE("GPL"); 37 38 #define BUF_SIZE 256 39 40 struct joydump { 41 unsigned int time; 42 unsigned char data; 43 }; 44 45 static int joydump_connect(struct gameport *gameport, struct gameport_driver *drv) 46 { 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; 53 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); 57 58 if (gameport_open(gameport, drv, GAMEPORT_MODE_RAW)) { 59 60 printk(KERN_INFO "joydump: | Raw mode not available - trying cooked. |\n"); 61 62 if (gameport_open(gameport, drv, GAMEPORT_MODE_COOKED)) { 63 64 printk(KERN_INFO "joydump: | Cooked not available either. Failing. |\n"); 65 printk(KERN_INFO "joydump: `------------------- END -----------------'\n"); 66 return -ENODEV; 67 } 68 69 gameport_cooked_read(gameport, axes, &buttons); 70 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"); 75 } 76 77 timeout = gameport_time(gameport, 10000); /* 10 ms */ 78 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; 83 } 84 dump = buf; 85 t = 0; 86 i = 1; 87 88 local_irq_save(flags); 89 90 u = gameport_read(gameport); 91 92 dump->data = u; 93 dump->time = t; 94 dump++; 95 96 gameport_trigger(gameport); 97 98 while (i < BUF_SIZE && t < timeout) { 99 100 dump->data = gameport_read(gameport); 101 102 if (dump->data ^ u) { 103 u = dump->data; 104 dump->time = t; 105 i++; 106 dump++; 107 } 108 t++; 109 } 110 111 local_irq_restore(flags); 112 113 /* 114 * Dump data. 115 */ 116 117 t = i; 118 dump = buf; 119 prev = dump; 120 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++; 127 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"); 134 } 135 kfree(buf); 136 137 jd_end: 138 printk(KERN_INFO "joydump: `------------------- END -----------------'\n"); 139 140 return 0; 141 } 142 143 static void joydump_disconnect(struct gameport *gameport) 144 { 145 gameport_close(gameport); 146 } 147 148 static struct gameport_driver joydump_drv = { 149 .driver = { 150 .name = "joydump", 151 }, 152 .description = DRIVER_DESC, 153 .connect = joydump_connect, 154 .disconnect = joydump_disconnect, 155 }; 156 157 module_gameport_driver(joydump_drv); 158