2 * $Id: warrior.c,v 1.1.1.1 2005/04/11 02:50:21 jack Exp $
4 * Copyright (c) 1999-2000 Vojtech Pavlik
10 * Logitech WingMan Warrior joystick driver for Linux
14 * This program is free warftware; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 * Should you need to contact me, the author, you can do so either by
29 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
30 * Vojtech Pavlik, Ucitelska 1576, Prague 8, 182 00 Czech Republic
33 #include <linux/kernel.h>
34 #include <linux/module.h>
35 #include <linux/slab.h>
36 #include <linux/input.h>
37 #include <linux/serio.h>
38 #include <linux/init.h>
44 #define WARRIOR_MAX_LENGTH 16
45 static char warrior_lengths[] = { 0, 4, 12, 3, 4, 4, 0, 0 };
46 static char *warrior_name = "Logitech WingMan Warrior";
55 unsigned char data[WARRIOR_MAX_LENGTH];
59 * warrior_process_packet() decodes packets the driver receives from the
60 * Warrior. It updates the data accordingly.
63 static void warrior_process_packet(struct warrior *warrior)
65 struct input_dev *dev = &warrior->dev;
66 unsigned char *data = warrior->data;
68 if (!warrior->idx) return;
70 switch ((data[0] >> 4) & 7) {
71 case 1: /* Button data */
72 input_report_key(dev, BTN_TRIGGER, data[3] & 1);
73 input_report_key(dev, BTN_THUMB, (data[3] >> 1) & 1);
74 input_report_key(dev, BTN_TOP, (data[3] >> 2) & 1);
75 input_report_key(dev, BTN_TOP2, (data[3] >> 3) & 1);
77 case 3: /* XY-axis info->data */
78 input_report_abs(dev, ABS_X, ((data[0] & 8) << 5) - (data[2] | ((data[0] & 4) << 5)));
79 input_report_abs(dev, ABS_Y, (data[1] | ((data[0] & 1) << 7)) - ((data[0] & 2) << 7));
81 case 5: /* Throttle, spinner, hat info->data */
82 input_report_abs(dev, ABS_THROTTLE, (data[1] | ((data[0] & 1) << 7)) - ((data[0] & 2) << 7));
83 input_report_abs(dev, ABS_HAT0X, (data[3] & 2 ? 1 : 0) - (data[3] & 1 ? 1 : 0));
84 input_report_abs(dev, ABS_HAT0Y, (data[3] & 8 ? 1 : 0) - (data[3] & 4 ? 1 : 0));
85 input_report_rel(dev, REL_DIAL, (data[2] | ((data[0] & 4) << 5)) - ((data[0] & 8) << 5));
91 * warrior_interrupt() is called by the low level driver when characters
92 * are ready for us. We then buffer them for further processing, or call the
93 * packet processing routine.
96 static void warrior_interrupt(struct serio *serio, unsigned char data, unsigned int flags)
98 struct warrior* warrior = serio->private;
101 if (warrior->idx) warrior_process_packet(warrior);
103 warrior->len = warrior_lengths[(data >> 4) & 7];
106 if (warrior->idx < warrior->len)
107 warrior->data[warrior->idx++] = data;
109 if (warrior->idx == warrior->len) {
110 if (warrior->idx) warrior_process_packet(warrior);
117 * warrior_disconnect() is the opposite of warrior_connect()
120 static void warrior_disconnect(struct serio *serio)
122 struct warrior* warrior = serio->private;
123 input_unregister_device(&warrior->dev);
129 * warrior_connect() is the routine that is called when someone adds a
130 * new serio device. It looks for the Warrior, and if found, registers
131 * it as an input device.
134 static void warrior_connect(struct serio *serio, struct serio_dev *dev)
136 struct warrior *warrior;
139 if (serio->type != (SERIO_RS232 | SERIO_WARRIOR))
142 if (!(warrior = kmalloc(sizeof(struct warrior), GFP_KERNEL)))
145 memset(warrior, 0, sizeof(struct warrior));
147 warrior->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REL) | BIT(EV_ABS);
148 warrior->dev.keybit[LONG(BTN_TRIGGER)] = BIT(BTN_TRIGGER) | BIT(BTN_THUMB) | BIT(BTN_TOP) | BIT(BTN_TOP2);
149 warrior->dev.relbit[0] = BIT(REL_DIAL);
150 warrior->dev.absbit[0] = BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_THROTTLE) | BIT(ABS_HAT0X) | BIT(ABS_HAT0Y);
152 warrior->dev.name = warrior_name;
153 warrior->dev.idbus = BUS_RS232;
154 warrior->dev.idvendor = SERIO_WARRIOR;
155 warrior->dev.idproduct = 0x0001;
156 warrior->dev.idversion = 0x0100;
158 for (i = 0; i < 2; i++) {
159 warrior->dev.absmax[ABS_X+i] = -64;
160 warrior->dev.absmin[ABS_X+i] = 64;
161 warrior->dev.absflat[ABS_X+i] = 8;
164 warrior->dev.absmax[ABS_THROTTLE] = -112;
165 warrior->dev.absmin[ABS_THROTTLE] = 112;
167 for (i = 0; i < 2; i++) {
168 warrior->dev.absmax[ABS_HAT0X+i] = -1;
169 warrior->dev.absmin[ABS_HAT0X+i] = 1;
172 warrior->dev.private = warrior;
174 serio->private = warrior;
176 if (serio_open(serio, dev)) {
181 input_register_device(&warrior->dev);
183 printk(KERN_INFO "input%d: Logitech WingMan Warrior on serio%d\n", warrior->dev.number, serio->number);
187 * The serio device structure.
190 static struct serio_dev warrior_dev = {
191 interrupt: warrior_interrupt,
192 connect: warrior_connect,
193 disconnect: warrior_disconnect,
197 * The functions for inserting/removing us as a module.
200 int __init warrior_init(void)
202 serio_register_device(&warrior_dev);
206 void __exit warrior_exit(void)
208 serio_unregister_device(&warrior_dev);
211 module_init(warrior_init);
212 module_exit(warrior_exit);
214 MODULE_LICENSE("GPL");