29 #include <linux/kernel.h>
30 #include <linux/module.h>
31 #include <linux/slab.h>
33 #include <linux/gameport.h>
34 #include <linux/input.h>
37 #define DRIVER_DESC "Creative Labs Blaster GamePad Cobra driver"
43 #define COBRA_MAX_STROBE 45
44 #define COBRA_LENGTH 36
46 static int cobra_btn[] = {
BTN_START,
BTN_SELECT,
BTN_TL,
BTN_TR,
BTN_X,
BTN_Y,
BTN_Z,
BTN_A,
BTN_B,
BTN_C,
BTN_TL2,
BTN_TR2, 0 };
50 struct input_dev *
dev[2];
60 unsigned char u,
v,
w;
67 for (i = 0; i < 2; i++) {
74 u = gameport_read(gameport);
78 v = gameport_read(gameport);
79 for (i = 0, w = u ^ v; i < 2 && w; i++, w >>= 2)
81 if ((w & 0x30) < 0x30 && r[i] <
COBRA_LENGTH && t[i] > 0) {
82 buf[
i] |= (
__u64)((w >> 5) & 1) << r[i]++;
87 }
while (t[0] > 0 || t[1] > 0);
93 for (i = 0; i < 2; i++) {
97 for (j = 0; j <
COBRA_LENGTH && (buf[
i] & 0x04104107f) ^ 0x041041040; j++)
102 data[
i] = ((buf[
i] >> 7) & 0x000001f) | ((buf[
i] >> 8) & 0x00003e0)
103 | ((buf[
i] >> 9) & 0x0007c00) | ((buf[
i] >> 10) & 0x00f8000)
104 | ((buf[
i] >> 11) & 0x1f00000);
111 static void cobra_poll(
struct gameport *gameport)
113 struct cobra *
cobra = gameport_get_drvdata(gameport);
114 struct input_dev *
dev;
115 unsigned int data[2];
120 if ((r = cobra_read_packet(gameport, data)) != cobra->
exists) {
125 for (i = 0; i < 2; i++)
126 if (cobra->
exists & r & (1 << i)) {
130 input_report_abs(dev,
ABS_X, ((data[i] >> 4) & 1) - ((data[i] >> 3) & 1));
131 input_report_abs(dev,
ABS_Y, ((data[i] >> 2) & 1) - ((data[i] >> 1) & 1));
133 for (j = 0; cobra_btn[
j]; j++)
134 input_report_key(dev, cobra_btn[j], data[i] & (0x20 << j));
141 static int cobra_open(
struct input_dev *dev)
143 struct cobra *cobra = input_get_drvdata(dev);
149 static void cobra_close(
struct input_dev *dev)
151 struct cobra *cobra = input_get_drvdata(dev);
156 static int cobra_connect(
struct gameport *gameport,
struct gameport_driver *drv)
159 struct input_dev *input_dev;
160 unsigned int data[2];
164 cobra = kzalloc(
sizeof(
struct cobra),
GFP_KERNEL);
170 gameport_set_drvdata(gameport, cobra);
176 cobra->
exists = cobra_read_packet(gameport, data);
178 for (i = 0; i < 2; i++)
179 if ((cobra->
exists >> i) & data[i] & 1) {
190 gameport_set_poll_handler(gameport, cobra_poll);
191 gameport_set_poll_interval(gameport, 20);
193 for (i = 0; i < 2; i++) {
194 if (~(cobra->
exists >> i) & 1)
197 cobra->
dev[
i] = input_dev = input_allocate_device();
204 "%s/input%d", gameport->
phys, i);
206 input_dev->name =
"Creative Labs Blaster GamePad Cobra";
207 input_dev->phys = cobra->
phys[
i];
210 input_dev->id.product = 0x0008;
211 input_dev->id.version = 0x0100;
212 input_dev->dev.parent = &gameport->
dev;
214 input_set_drvdata(input_dev, cobra);
216 input_dev->open = cobra_open;
217 input_dev->close = cobra_close;
220 input_set_abs_params(input_dev,
ABS_X, -1, 1, 0, 0);
221 input_set_abs_params(input_dev,
ABS_Y, -1, 1, 0, 0);
222 for (j = 0; cobra_btn[
j]; j++)
223 set_bit(cobra_btn[j], input_dev->keybit);
225 err = input_register_device(cobra->
dev[i]);
232 fail4: input_free_device(cobra->
dev[i]);
233 fail3:
while (--i >= 0)
235 input_unregister_device(cobra->
dev[i]);
237 fail1: gameport_set_drvdata(gameport,
NULL);
242 static void cobra_disconnect(
struct gameport *gameport)
244 struct cobra *cobra = gameport_get_drvdata(gameport);
247 for (i = 0; i < 2; i++)
248 if ((cobra->
exists >> i) & 1)
249 input_unregister_device(cobra->
dev[i]);
251 gameport_set_drvdata(gameport,
NULL);
260 .connect = cobra_connect,
261 .disconnect = cobra_disconnect,