2 * $Id: stinger.c,v 1.10 2002/01/22 20:29:31 vojtech Exp $
4 * Copyright (c) 2000-2001 Vojtech Pavlik
5 * Copyright (c) 2000 Mark Fletcher
9 * Gravis Stinger gamepad driver for Linux
13 * This program is free warftware; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 * Should you need to contact me, the author, you can do so either by
28 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
29 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
32 #include <linux/kernel.h>
33 #include <linux/module.h>
34 #include <linux/slab.h>
35 #include <linux/input.h>
36 #include <linux/serio.h>
37 #include <linux/init.h>
39 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
40 MODULE_DESCRIPTION("Gravis Stinger gamepad driver");
41 MODULE_LICENSE("GPL");
47 #define STINGER_MAX_LENGTH 8
49 static char *stinger_name = "Gravis Stinger";
58 unsigned char data[STINGER_MAX_LENGTH];
63 * stinger_process_packet() decodes packets the driver receives from the
64 * Stinger. It updates the data accordingly.
67 static void stinger_process_packet(struct stinger *stinger, struct pt_regs *regs)
69 struct input_dev *dev = &stinger->dev;
70 unsigned char *data = stinger->data;
72 if (!stinger->idx) return;
74 input_regs(dev, regs);
76 input_report_key(dev, BTN_A, ((data[0] & 0x20) >> 5));
77 input_report_key(dev, BTN_B, ((data[0] & 0x10) >> 4));
78 input_report_key(dev, BTN_C, ((data[0] & 0x08) >> 3));
79 input_report_key(dev, BTN_X, ((data[0] & 0x04) >> 2));
80 input_report_key(dev, BTN_Y, ((data[3] & 0x20) >> 5));
81 input_report_key(dev, BTN_Z, ((data[3] & 0x10) >> 4));
82 input_report_key(dev, BTN_TL, ((data[3] & 0x08) >> 3));
83 input_report_key(dev, BTN_TR, ((data[3] & 0x04) >> 2));
84 input_report_key(dev, BTN_SELECT, ((data[3] & 0x02) >> 1));
85 input_report_key(dev, BTN_START, (data[3] & 0x01));
87 input_report_abs(dev, ABS_X, (data[1] & 0x3F) - ((data[0] & 0x01) << 6));
88 input_report_abs(dev, ABS_Y, ((data[0] & 0x02) << 5) - (data[2] & 0x3F));
96 * stinger_interrupt() is called by the low level driver when characters
97 * are ready for us. We then buffer them for further processing, or call the
98 * packet processing routine.
101 static irqreturn_t stinger_interrupt(struct serio *serio,
102 unsigned char data, unsigned int flags, struct pt_regs *regs)
104 struct stinger* stinger = serio->private;
106 /* All Stinger packets are 4 bytes */
108 if (stinger->idx < STINGER_MAX_LENGTH)
109 stinger->data[stinger->idx++] = data;
111 if (stinger->idx == 4) {
112 stinger_process_packet(stinger, regs);
120 * stinger_disconnect() is the opposite of stinger_connect()
123 static void stinger_disconnect(struct serio *serio)
125 struct stinger* stinger = serio->private;
126 input_unregister_device(&stinger->dev);
132 * stinger_connect() is the routine that is called when someone adds a
133 * new serio device. It looks for the Stinger, and if found, registers
134 * it as an input device.
137 static void stinger_connect(struct serio *serio, struct serio_dev *dev)
139 struct stinger *stinger;
142 if (serio->type != (SERIO_RS232 | SERIO_STINGER))
145 if (!(stinger = kmalloc(sizeof(struct stinger), GFP_KERNEL)))
148 memset(stinger, 0, sizeof(struct stinger));
150 stinger->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
151 stinger->dev.keybit[LONG(BTN_A)] = BIT(BTN_A) | BIT(BTN_B) | BIT(BTN_C) | BIT(BTN_X) | \
152 BIT(BTN_Y) | BIT(BTN_Z) | BIT(BTN_TL) | BIT(BTN_TR) | \
153 BIT(BTN_START) | BIT(BTN_SELECT);
154 stinger->dev.absbit[0] = BIT(ABS_X) | BIT(ABS_Y);
156 sprintf(stinger->phys, "%s/serio0", serio->phys);
158 init_input_dev(&stinger->dev);
159 stinger->dev.name = stinger_name;
160 stinger->dev.phys = stinger->phys;
161 stinger->dev.id.bustype = BUS_RS232;
162 stinger->dev.id.vendor = SERIO_STINGER;
163 stinger->dev.id.product = 0x0001;
164 stinger->dev.id.version = 0x0100;
166 for (i = 0; i < 2; i++) {
167 stinger->dev.absmax[ABS_X+i] = 64;
168 stinger->dev.absmin[ABS_X+i] = -64;
169 stinger->dev.absflat[ABS_X+i] = 4;
172 stinger->dev.private = stinger;
173 serio->private = stinger;
175 if (serio_open(serio, dev)) {
180 input_register_device(&stinger->dev);
182 printk(KERN_INFO "input: %s on %s\n", stinger_name, serio->phys);
187 * The serio device structure.
190 static struct serio_dev stinger_dev = {
191 .interrupt = stinger_interrupt,
192 .connect = stinger_connect,
193 .disconnect = stinger_disconnect,
197 * The functions for inserting/removing us as a module.
200 int __init stinger_init(void)
202 serio_register_device(&stinger_dev);
206 void __exit stinger_exit(void)
208 serio_unregister_device(&stinger_dev);
211 module_init(stinger_init);
212 module_exit(stinger_exit);