29 #include <linux/kernel.h>
30 #include <linux/module.h>
31 #include <linux/slab.h>
32 #include <linux/input.h>
33 #include <linux/serio.h>
36 #define DRIVER_DESC "Logitech WingMan Warrior joystick driver"
46 #define WARRIOR_MAX_LENGTH 16
47 static char warrior_lengths[] = { 0, 4, 12, 3, 4, 4, 0, 0 };
54 struct input_dev *
dev;
67 struct input_dev *
dev = warrior->
dev;
70 if (!warrior->
idx)
return;
72 switch ((data[0] >> 4) & 7) {
75 input_report_key(dev,
BTN_THUMB, (data[3] >> 1) & 1);
76 input_report_key(dev,
BTN_TOP, (data[3] >> 2) & 1);
77 input_report_key(dev,
BTN_TOP2, (data[3] >> 3) & 1);
80 input_report_abs(dev,
ABS_X, ((data[0] & 8) << 5) - (data[2] | ((data[0] & 4) << 5)));
81 input_report_abs(dev,
ABS_Y, (data[1] | ((data[0] & 1) << 7)) - ((data[0] & 2) << 7));
84 input_report_abs(dev,
ABS_THROTTLE, (data[1] | ((data[0] & 1) << 7)) - ((data[0] & 2) << 7));
85 input_report_abs(dev,
ABS_HAT0X, (data[3] & 2 ? 1 : 0) - (data[3] & 1 ? 1 : 0));
86 input_report_abs(dev,
ABS_HAT0Y, (data[3] & 8 ? 1 : 0) - (data[3] & 4 ? 1 : 0));
87 input_report_rel(dev,
REL_DIAL, (data[2] | ((data[0] & 4) << 5)) - ((data[0] & 8) << 5));
105 if (warrior->
idx) warrior_process_packet(warrior);
107 warrior->
len = warrior_lengths[(data >> 4) & 7];
110 if (warrior->
idx < warrior->
len)
113 if (warrior->
idx == warrior->
len) {
114 if (warrior->
idx) warrior_process_packet(warrior);
125 static void warrior_disconnect(
struct serio *serio)
127 struct warrior *warrior = serio_get_drvdata(serio);
130 serio_set_drvdata(serio,
NULL);
131 input_unregister_device(warrior->
dev);
141 static int warrior_connect(
struct serio *serio,
struct serio_driver *drv)
143 struct warrior *warrior;
144 struct input_dev *input_dev;
147 warrior = kzalloc(
sizeof(
struct warrior),
GFP_KERNEL);
148 input_dev = input_allocate_device();
149 if (!warrior || !input_dev)
152 warrior->
dev = input_dev;
155 input_dev->name =
"Logitech WingMan Warrior";
156 input_dev->phys = warrior->
phys;
159 input_dev->id.product = 0x0001;
160 input_dev->id.version = 0x0100;
161 input_dev->dev.parent = &serio->
dev;
168 input_set_abs_params(input_dev,
ABS_X, -64, 64, 0, 8);
169 input_set_abs_params(input_dev,
ABS_Y, -64, 64, 0, 8);
170 input_set_abs_params(input_dev,
ABS_THROTTLE, -112, 112, 0, 0);
171 input_set_abs_params(input_dev,
ABS_HAT0X, -1, 1, 0, 0);
172 input_set_abs_params(input_dev,
ABS_HAT0Y, -1, 1, 0, 0);
174 serio_set_drvdata(serio, warrior);
180 err = input_register_device(warrior->
dev);
187 fail2: serio_set_drvdata(serio,
NULL);
188 fail1: input_free_device(input_dev);
214 .id_table = warrior_serio_ids,
215 .interrupt = warrior_interrupt,
216 .connect = warrior_connect,
217 .disconnect = warrior_disconnect,